From 968f13f9ef6fff342164b0170d072b035a060cb3 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 13 Apr 2023 23:10:39 -0400 Subject: [PATCH] Set `Context._scope_nursery` on callee side too Because obviously we probably want to support `allow_overruns` on the remote callee side as well XD Only found the bugs fixed in this patch this thanks to writing a much more exhaustive test set for overrun cases B) --- tractor/_runtime.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tractor/_runtime.py b/tractor/_runtime.py index 9d9427d..5bc8b1f 100644 --- a/tractor/_runtime.py +++ b/tractor/_runtime.py @@ -205,8 +205,9 @@ async def _invoke( await chan.send({'functype': 'context', 'cid': cid}) try: - with cancel_scope as cs: - ctx._scope = cs + async with trio.open_nursery() as nurse: + ctx._scope_nursery = nurse + ctx._scope = nurse.cancel_scope task_status.started(ctx) res = await coro await chan.send({'return': res, 'cid': cid}) @@ -240,8 +241,7 @@ async def _invoke( f'Context entrypoint {func} was terminated:\n{ctx}' ) - assert cs - if cs.cancelled_caught: + if ctx.cancelled_caught: # first check for and raise any remote error # before raising any context cancelled case @@ -252,6 +252,7 @@ async def _invoke( ctx._maybe_raise_remote_err(re) fname = func.__name__ + cs: trio.CancelScope = ctx._scope if cs.cancel_called: canceller = ctx._cancel_called_remote # await _debug.breakpoint() @@ -383,7 +384,7 @@ async def _invoke( # error is probably from above coro running code *not from the # underlyingn rpc invocation* since a scope was never allocated # around actual coroutine await. - if cs is None: + if ctx._scope is None: # we don't ever raise directly here to allow the # msg-loop-scheduler to continue running for this # channel.