Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle exceptions from server callbacks #337

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion capnp/lib/capnp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2475,10 +2475,24 @@ cdef class _PyAsyncIoStreamProtocol(DummyBaseClass, asyncio.BufferedProtocol):
self.write_in_progress = False
self.read_eof = False
self.read_overflow_buffer = bytearray()
def done(task):
if self.transport is not None:
self.transport.close()
exc = task.exception()
if exc is not None:
context = {
'message': "Exception in pycapnp server callback",
'exception': exc,
'task': task,
'protocol': self,
'transport': self.transport
}
asyncio.get_running_loop().call_exception_handler(context)
if self.connected_callback is not None:
callback_res = self.connected_callback(self.callback_arg)
if asyncio.iscoroutine(callback_res):
self._task = asyncio.get_running_loop().create_task(callback_res)
self._task = asyncio.create_task(callback_res)
self._task.add_done_callback(done)
self.connected_callback = None
self.callback_arg = None

Expand Down
Loading