Commit 07cae4e9 authored by Kirill Smelkov's avatar Kirill Smelkov

libgolang/gevent: Put explicit try/catch boundary for tasks spawned via go

Else as https://github.com/python-greenlet/greenlet/pull/285
demonstrates there can be segmentation faults and crashes due to
exceptions from one greenlet propagating to C stack of another greenlet.

No test here. I've tried to do it, but with gevent (contrary to plain
greenlets), spawning new task only schedules corresponding greenlet to
run in the end of current event loop cycle instead of switching to
created greenlet immediately. With this delaying, it was hard for me to
develop corresponding test in a reasonable time.

Hopefully having the test I've done for greenlet itself + hereby
protection is good enough.

/reviewed-on !17
parent d358fa75
# cython: language_level=2 # cython: language_level=2
# Copyright (C) 2019-2020 Nexedi SA and Contributors. # Copyright (C) 2019-2022 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -48,12 +48,17 @@ from golang.runtime._libgolang cimport _libgolang_runtime_ops, _libgolang_sema, ...@@ -48,12 +48,17 @@ from golang.runtime._libgolang cimport _libgolang_runtime_ops, _libgolang_sema,
STACK_DEAD_WHILE_PARKED, panic STACK_DEAD_WHILE_PARKED, panic
from golang.runtime cimport _runtime_thread from golang.runtime cimport _runtime_thread
from golang.runtime._runtime_pymisc cimport PyExc, pyexc_fetch, pyexc_restore from golang.runtime._runtime_pymisc cimport PyExc, pyexc_fetch, pyexc_restore
from golang cimport topyexc
# _goviapy & _togo serve go # _goviapy & _togo serve go
def _goviapy(_togo _ not None): def _goviapy(_togo _ not None):
with nogil: with nogil:
_.f(_.arg) # run _.f in try/catch to workaround https://github.com/python-greenlet/greenlet/pull/285
__goviapy(_.f, _.arg)
cdef nogil:
void __goviapy(void (*f)(void *) nogil, void *arg) except +topyexc:
f(arg)
@final @final
cdef class _togo: cdef class _togo:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment