File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 99from aiochannel .errors import ChannelClosed
1010from opentelemetry .trace import Span
1111from websockets .asyncio .client import ClientConnection
12- from websockets .exceptions import ConnectionClosed
12+ from websockets .exceptions import ConnectionClosed , ConnectionClosedOK
1313from websockets .frames import CloseCode
1414from websockets .legacy .protocol import WebSocketCommonProtocol
1515
@@ -156,7 +156,11 @@ async def _handle_messages_from_ws(self) -> None:
156156 )
157157 try :
158158 ws = self ._ws_unwrapped
159- async for message in ws :
159+ while True :
160+ # decode=False: Avoiding an unnecessary round-trip through str
161+ # Ideally this should be type-ascripted to : bytes, but there is no
162+ # @overrides in `websockets` to hint this.
163+ message = await ws .recv (decode = False )
160164 try :
161165 if not self ._ws_unwrapped :
162166 # We should not process messages if the websocket is closed.
@@ -241,6 +245,8 @@ async def _handle_messages_from_ws(self) -> None:
241245 logger .exception ("Got invalid transport message, closing session" )
242246 await self .close ()
243247 return
248+ except ConnectionClosedOK :
249+ pass # Exited normally
244250 except ConnectionClosed as e :
245251 raise e
246252
You can’t perform that action at this time.
0 commit comments