From e2139c2bf0c2fc49f9475dc753843e5bd1704c5c Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 14 Dec 2021 23:05:30 -0500 Subject: [PATCH] Don't set `Context._error` to expected `ContextCancelled` If the one side of an inter-actor context cancels the other then that side should always expect back a `ContextCancelled` message. However we should not set this error in this case (where the cancel request was sent and a `ContextCancelled` msg was received back) since it may override some other error that caused the cancellation request to be sent out in the first place. As an example when a context opens another context to a peer and some error happens which causes the second peer context to be cancelled but we want to propagate the original error. Fixes the issue found in https://github.com/pikers/piker/issues/244 --- tractor/_streaming.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tractor/_streaming.py b/tractor/_streaming.py index 86060b9..47fd08a 100644 --- a/tractor/_streaming.py +++ b/tractor/_streaming.py @@ -425,7 +425,17 @@ class Context: f'Remote context error for {self.chan.uid}:{self.cid}:\n' f'{msg["error"]["tb_str"]}' ) - self._error = unpack_error(msg, self.chan) + error = unpack_error(msg, self.chan) + if ( + isinstance(error, ContextCancelled) and + self._cancel_called + ): + # this is an expected cancel request response message + # and we don't need to raise it in scope since it will + # potentially override a real error + return + + self._error = error # TODO: tempted to **not** do this by-reraising in a # nursery and instead cancel a surrounding scope, detect