Skip to content

Commit

Permalink
Corner case for cancelled server methods that raise exceptions
Browse files Browse the repository at this point in the history
When a server method is cancelled, but it nonetheless raises an exception (other
than `CancelledError`), this exception cannot be reported to the caller (because
it has cancelled that call).

The only place where it can go is to the asyncio exception handler...
  • Loading branch information
LasseBlaauwbroek authored and haata committed Nov 9, 2023
1 parent 0ec4d0b commit b6ea909
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions capnp/lib/capnp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ cdef class _VoidPromiseFulfiller:

def void_task_done_callback(method_name, _VoidPromiseFulfiller fulfiller, task):
if fulfiller.fulfiller == NULL:
if not task.cancelled():
exc = task.exception()
if exc is not None:
context = {
'message': f"Cancelled server method {method_name} raised an exception",
'exception': exc,
'task': task,
}
asyncio.get_running_loop().call_exception_handler(context)
return

if task.cancelled():
Expand Down

0 comments on commit b6ea909

Please sign in to comment.