Wrap `open_autorecon_ws()` body for comms failures

Add outer `try/except` around the nursery block in
`open_autorecon_ws()` to catch any `NoBsWs.recon_errors` that
escape the inner reconnect loop, logging a warning instead of
propagating.

Also,
- correct `NoBsWs.recon_errors` typing to `tuple[Type[Exception]]`.

(this commit msg was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
tpt_closed_and_finally_footguns
Gud Boi 2026-02-18 13:37:47 -05:00
parent 6f390dc88c
commit 3d83b61f3f
1 changed files with 32 additions and 24 deletions

View File

@ -31,6 +31,7 @@ from typing import (
AsyncContextManager, AsyncContextManager,
AsyncGenerator, AsyncGenerator,
Iterable, Iterable,
Type,
) )
import json import json
@ -67,7 +68,7 @@ class NoBsWs:
''' '''
# apparently we can QoS for all sorts of reasons..so catch em. # apparently we can QoS for all sorts of reasons..so catch em.
recon_errors = ( recon_errors: tuple[Type[Exception]] = (
ConnectionClosed, ConnectionClosed,
DisconnectionTimeout, DisconnectionTimeout,
ConnectionRejected, ConnectionRejected,
@ -370,32 +371,39 @@ async def open_autorecon_ws(
rcv: trio.MemoryReceiveChannel rcv: trio.MemoryReceiveChannel
snd, rcv = trio.open_memory_channel(616) snd, rcv = trio.open_memory_channel(616)
async with ( try:
tractor.trionics.collapse_eg(), async with (
trio.open_nursery() as tn tractor.trionics.collapse_eg(),
): trio.open_nursery() as tn
nobsws = NoBsWs( ):
url, nobsws = NoBsWs(
rcv,
msg_recv_timeout=msg_recv_timeout,
)
await tn.start(
partial(
_reconnect_forever,
url, url,
snd, rcv,
nobsws, msg_recv_timeout=msg_recv_timeout,
fixture=fixture,
reset_after=reset_after,
) )
await tn.start(
partial(
_reconnect_forever,
url,
snd,
nobsws,
fixture=fixture,
reset_after=reset_after,
)
)
await nobsws._connected.wait()
assert nobsws._cs
assert nobsws.connected()
try:
yield nobsws
finally:
tn.cancel_scope.cancel()
except NoBsWs.recon_errors as con_err:
log.warning(
f'Entire ws-channel disconnect due to,\n'
f'con_err: {con_err!r}\n'
) )
await nobsws._connected.wait()
assert nobsws._cs
assert nobsws.connected()
try:
yield nobsws
finally:
tn.cancel_scope.cancel()
''' '''