Skip to content

Handle asyncio's Task cancellation and aiohttp's websock close properly #13

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

Merged
merged 1 commit into from
Jun 22, 2018
Merged

Conversation

ciscorn
Copy link
Contributor

@ciscorn ciscorn commented Jun 2, 2018

The current implementation doesn’t manage asyncio.Task and aiohttp.WebSocketResponce properly, which causes the following errors frequently.

Task was destroyed but it is pending!
task: <Task pending coro=<AiohttpSubscriptionServer.on_start() done, defined at ../graphql_ws/aiohttp.py:80> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x104eadca8>()]>>
Task exception was never retrieved
future: <Task finished coro=<AiohttpSubscriptionServer.on_start() done, defined at ../graphql_ws/aiohttp.py:80> exception=RuntimeError('unable to perform operation on <TCPTransport closed=True reading=False 0x7fdafc90d938>; the handler is closed',)>

This problem also prevents the app from performing graceful shutdown/reloading in some situations.

@ciscorn ciscorn changed the title Handle asyncio's Task cancellation and socket close properly Handle asyncio's Task cancellation and aiohttp's websock close properly Jun 2, 2018
for task in pending_tasks:
if not task.done():
task.cancel()
await wait(pending_tasks, loop=self.loop)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All pending tasks should be cancelled and awaited.

elif msg.type == WSMsgType.CLOSING:
raise ConnectionClosedException()
elif msg.type == WSMsgType.CLOSED:
raise ConnectionClosedException()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code raises ConnectionClosedException only when msg.type == WSMsgType.ERROR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants