diff --git a/piker/data/_web_bs.py b/piker/data/_web_bs.py index b7a5fb32..fde04e71 100644 --- a/piker/data/_web_bs.py +++ b/piker/data/_web_bs.py @@ -31,6 +31,7 @@ from typing import ( AsyncContextManager, AsyncGenerator, Iterable, + Type, ) import json @@ -67,7 +68,7 @@ class NoBsWs: ''' # apparently we can QoS for all sorts of reasons..so catch em. - recon_errors = ( + recon_errors: tuple[Type[Exception]] = ( ConnectionClosed, DisconnectionTimeout, ConnectionRejected, @@ -370,32 +371,39 @@ async def open_autorecon_ws( rcv: trio.MemoryReceiveChannel snd, rcv = trio.open_memory_channel(616) - async with ( - tractor.trionics.collapse_eg(), - trio.open_nursery() as tn - ): - nobsws = NoBsWs( - url, - rcv, - msg_recv_timeout=msg_recv_timeout, - ) - await tn.start( - partial( - _reconnect_forever, + try: + async with ( + tractor.trionics.collapse_eg(), + trio.open_nursery() as tn + ): + nobsws = NoBsWs( url, - snd, - nobsws, - fixture=fixture, - reset_after=reset_after, + rcv, + msg_recv_timeout=msg_recv_timeout, ) + 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() '''