From c35576e196b38bedd725edd7eb73b137dad9806b Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 19 Feb 2024 14:41:03 -0500 Subject: [PATCH] Baboso! fix `chan.send(None)` indent.. --- tractor/_runtime.py | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/tractor/_runtime.py b/tractor/_runtime.py index f25d3e5..4e7f9fa 100644 --- a/tractor/_runtime.py +++ b/tractor/_runtime.py @@ -1113,23 +1113,32 @@ class Actor: db_cs.cancel() # XXX: is this necessary (GC should do it)? - if chan.connected(): - # if the channel is still connected it may mean the far - # end has not closed and we may have gotten here due to - # an error and so we should at least try to terminate - # the channel from this end gracefully. + # XXX WARNING XXX + # Be AWARE OF THE INDENT LEVEL HERE + # -> ONLY ENTER THIS BLOCK WHEN ._peers IS + # EMPTY!!!! + if ( + not self._peers + and chan.connected() + ): + # if the channel is still connected it may mean the far + # end has not closed and we may have gotten here due to + # an error and so we should at least try to terminate + # the channel from this end gracefully. + log.runtime( + 'Terminating channel with `None` setinel msg\n' + f'|_{chan}\n' + ) + try: + # send a msg loop terminate sentinel + await chan.send(None) - log.runtime(f"Disconnecting channel {chan}") - try: - # send a msg loop terminate sentinel - await chan.send(None) + # XXX: do we want this? + # causes "[104] connection reset by peer" on other end + # await chan.aclose() - # XXX: do we want this? - # causes "[104] connection reset by peer" on other end - # await chan.aclose() - - except trio.BrokenResourceError: - log.runtime(f"Channel {chan.uid} was already closed") + except trio.BrokenResourceError: + log.runtime(f"Channel {chan.uid} was already closed") async def _push_result( self,