From b72a025d0f554c2f6422c19efd7619cbbfae8537 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 28 Jun 2024 12:59:31 -0400 Subject: [PATCH] Always reset `._state._ctxvar_Context` to prior Not sure how I forgot this but, obviously it's correct context-var semantics to revert the current IPC `Context` (set in the latest `.open_context()` block) such that any prior instance is reset.. This ensures the sanity `assert`s pass inside `.msg._ops.maybe_limit_plds()` and just in general ensures for any task that the last opened `Context` is the one returned from `current_ipc_ctx()`. --- tractor/_context.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tractor/_context.py b/tractor/_context.py index 620363c..6b5f2eb 100644 --- a/tractor/_context.py +++ b/tractor/_context.py @@ -38,6 +38,7 @@ from collections import deque from contextlib import ( asynccontextmanager as acm, ) +from contextvars import Token from dataclasses import ( dataclass, field, @@ -1943,7 +1944,7 @@ async def open_context_from_portal( ) assert ctx._remote_func_type == 'context' assert ctx._caller_info - _ctxvar_Context.set(ctx) + prior_ctx_tok: Token = _ctxvar_Context.set(ctx) # placeholder for any exception raised in the runtime # or by user tasks which cause this context's closure. @@ -2394,6 +2395,9 @@ async def open_context_from_portal( None, ) + # XXX revert to prior IPC-task-ctx scope + _ctxvar_Context.reset(prior_ctx_tok) + def mk_context( chan: Channel,