Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix long hang under certain network failures #517

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion gql/transport/websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from graphql import DocumentNode, ExecutionResult, print_ast
from websockets.datastructures import HeadersLike
from websockets.exceptions import ConnectionClosed
from websockets.typing import Subprotocol

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

async def _close_hook(self):
log.debug("_close_hook: start")

# Properly shut down the send ping task if enabled
if self.send_ping_task is not None:
log.debug("_close_hook: cancelling send_ping_task")
self.send_ping_task.cancel()
with suppress(asyncio.CancelledError):
with suppress(asyncio.CancelledError, ConnectionClosed):
log.debug("_close_hook: awaiting send_ping_task")
await self.send_ping_task
self.send_ping_task = None

log.debug("_close_hook: end")
Loading