Skip to content

Commit f9e74e9

Browse files
committed
Fix assertion error when transport is already closed when _receive is called
1 parent fdb8307 commit f9e74e9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

gql/transport/websockets.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ async def _receive(self) -> str:
175175
"""Wait the next message from the websocket connection and log the answer
176176
"""
177177

178-
# We should always have an active websocket connection here
179-
assert self.websocket is not None
178+
# It is possible that the websocket has been already closed in another task
179+
if self.websocket is None:
180+
raise TransportClosed("Transport is already closed")
180181

181182
# Wait for the next websocket frame. Can raise ConnectionClosed
182183
data: Data = await self.websocket.recv()
@@ -387,6 +388,8 @@ async def _receive_data_loop(self) -> None:
387388
except (ConnectionClosed, TransportProtocolError) as e:
388389
await self._fail(e, clean_close=False)
389390
break
391+
except TransportClosed:
392+
break
390393

391394
# Parse the answer
392395
try:

0 commit comments

Comments
 (0)