Skip to content

Commit 212e2e1

Browse files
authored
Websockets transport Fix long hang under certain network failures (#517)
1 parent 26b28d7 commit 212e2e1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

gql/transport/websockets.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from graphql import DocumentNode, ExecutionResult, print_ast
99
from websockets.datastructures import HeadersLike
10+
from websockets.exceptions import ConnectionClosed
1011
from websockets.typing import Subprotocol
1112

1213
from .exceptions import (
@@ -505,10 +506,15 @@ async def _after_initialize(self):
505506
self.send_ping_task = asyncio.ensure_future(self._send_ping_coro())
506507

507508
async def _close_hook(self):
509+
log.debug("_close_hook: start")
508510

509511
# Properly shut down the send ping task if enabled
510512
if self.send_ping_task is not None:
513+
log.debug("_close_hook: cancelling send_ping_task")
511514
self.send_ping_task.cancel()
512-
with suppress(asyncio.CancelledError):
515+
with suppress(asyncio.CancelledError, ConnectionClosed):
516+
log.debug("_close_hook: awaiting send_ping_task")
513517
await self.send_ping_task
514518
self.send_ping_task = None
519+
520+
log.debug("_close_hook: end")

0 commit comments

Comments
 (0)