From 07c2ba5c0d4c7e3e83e83d36238e2385a99a6652 Mon Sep 17 00:00:00 2001 From: goodboy Date: Thu, 19 Feb 2026 13:10:02 -0500 Subject: [PATCH] Drop `trio`-exc-catching if tpt-closed covers them Remove the `trio.ClosedResourceError` and `trio.BrokenResourceError` handling that should now be subsumed by `TransportClosed` re-raising out of the `.ipc` stack. Deats, - drop CRE and BRE from `._streaming.MsgStream.aclose()/.send()` blocks. - similarly rm from `._context.open_context_from_portal()`. - also from `._portal.Portal.cancel_actor()` and drop the (now-completed-todo) comment about this exact thing. Also add comment in `._rpc.try_ship_error_to_remote()` noting the remaining `trio` catches there are bc the `.ipc` layers *should* be wrapping them; thus `log.critical()` use is warranted. (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- tractor/_context.py | 6 +----- tractor/_portal.py | 13 +------------ tractor/_rpc.py | 5 +++++ tractor/_streaming.py | 5 ----- 4 files changed, 7 insertions(+), 22 deletions(-) diff --git a/tractor/_context.py b/tractor/_context.py index c5b4afc5..5a69077e 100644 --- a/tractor/_context.py +++ b/tractor/_context.py @@ -2429,11 +2429,7 @@ async def open_context_from_portal( try: # await pause(shield=True) await ctx.cancel() - except ( - trio.BrokenResourceError, - trio.ClosedResourceError, - TransportClosed, - ): + except TransportClosed: log.warning( 'IPC connection for context is broken?\n' f'task: {ctx.cid}\n' diff --git a/tractor/_portal.py b/tractor/_portal.py index a914bb80..2fc9dbb7 100644 --- a/tractor/_portal.py +++ b/tractor/_portal.py @@ -329,18 +329,7 @@ class Portal: # if we get here some weird cancellation case happened return False - except ( - # XXX, should never really get raised unless we aren't - # wrapping them in the below type by mistake? - # - # Leaving the catch here for now until we're very sure - # all the cases (for various tpt protos) have indeed been - # re-wrapped ;p - trio.ClosedResourceError, - trio.BrokenResourceError, - - TransportClosed, - ) as tpt_err: + except TransportClosed as tpt_err: ipc_borked_report: str = ( f'IPC for actor already closed/broken?\n\n' f'\n' diff --git a/tractor/_rpc.py b/tractor/_rpc.py index 801ab672..bd26b5ed 100644 --- a/tractor/_rpc.py +++ b/tractor/_rpc.py @@ -935,6 +935,11 @@ async def try_ship_error_to_remote( # XXX NOTE XXX in SC terms this is one of the worst things # that can happen and provides for a 2-general's dilemma.. + # + # FURHTER, we should never really have to handle these + # lowlevel excs from `trio` since the `Channel.send()` layers + # downward should be mostly wrapping such cases in a + # tpt-closed; the `.critical()` usage is warranted. except ( trio.ClosedResourceError, trio.BrokenResourceError, diff --git a/tractor/_streaming.py b/tractor/_streaming.py index cf3eaab0..56e0607a 100644 --- a/tractor/_streaming.py +++ b/tractor/_streaming.py @@ -410,10 +410,7 @@ class MsgStream(trio.abc.Channel): # it). with trio.CancelScope(shield=True): await self._ctx.send_stop() - except ( - trio.BrokenResourceError, - trio.ClosedResourceError, TransportClosed, ) as re: # the underlying channel may already have been pulled @@ -595,8 +592,6 @@ class MsgStream(trio.abc.Channel): ), ) except ( - trio.ClosedResourceError, - trio.BrokenResourceError, BrokenPipeError, TransportClosed, ) as _trans_err: