From cbba7273606ec22cf10ed7ddea41de19822cbad6 Mon Sep 17 00:00:00 2001 From: "av.terehin" Date: Mon, 31 Jul 2023 09:41:46 +0300 Subject: [PATCH] Bugfix. When connection is closed or in closing - then no exception raised upstairs (silent loss of subscription for example). --- aioari/client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aioari/client.py b/aioari/client.py index 18d4dd8..d3e4a10 100644 --- a/aioari/client.py +++ b/aioari/client.py @@ -17,6 +17,10 @@ log = logging.getLogger(__name__) +class WSConnectionClosed(Exception): + pass + + class Client(object): """Async ARI Client object. @@ -103,8 +107,8 @@ async def __run(self, ws): msg = await ws.receive() if msg is None: return ## EOF - elif msg.type in {aiohttp.WSMsgType.CLOSED, aiohttp.WSMsgType.CLOSING}: - break + elif msg.type in {aiohttp.WSMsgType.CLOSE, aiohttp.WSMsgType.CLOSED, aiohttp.WSMsgType.CLOSING}: + raise WSConnectionClosed("WS connection closed") elif msg.type != aiohttp.WSMsgType.TEXT: log.warning("Unknown JSON message type: %s", repr(msg)) continue # ignore