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

Getting concurrent.futures._base.CancelledError on shutdown #64

Open
AutumnalDream opened this issue Oct 8, 2019 · 3 comments
Open
Labels
bug Something isn't working

Comments

@AutumnalDream
Copy link
Contributor

This is using the subscription example.
When searching I didn't see that the event loop was closed either but I'm not an async expert.

INFO: Started server process [86447]
INFO: Waiting for application startup.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: ('127.0.0.1', 61918) - "GET / HTTP/1.1" 200
INFO: ('127.0.0.1', 61920) - "WebSocket /subscriptions" [accepted]
INFO: ('127.0.0.1', 61918) - "POST / HTTP/1.1" 200
^CINFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Finished server process [86447]
ERROR: Task exception was never retrieved
future: <Task finished coro=<GraphQLWSProtocol._main() done, defined at ./tartiflette_starlette/subscriptions/protocol.py:99> exception=RuntimeError("Unexpected ASGI message 'websocket.send', after sending 'websocket.close'.")>
Traceback (most recent call last):
File "./tartiflette_starlette/subscriptions/protocol.py", line 58, in _subscribe
async for item in stream:
concurrent.futures._base.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "./tartiflette_starlette/subscriptions/protocol.py", line 119, in _main
await handler(opid=opid, payload=payload)
File "./tartiflette_starlette/subscriptions/protocol.py", line 89, in _on_start
await self._subscribe(opid, payload)
File "./tartiflette_starlette/subscriptions/protocol.py", line 63, in _subscribe
await self._send_error(Exception("Internal error"), opid=opid)
File "./tartiflette_starlette/subscriptions/protocol.py", line 51, in _send_error
await self._send_message(opid, error_type, {"message": str(exception)})
File "./tartiflette_starlette/subscriptions/protocol.py", line 41, in _send_message
await self.send_json(message)
File "./tartiflette_starlette/subscriptions/impl.py", line 31, in send_json
await self.websocket.send_json(message)
File "/X/tartiflette-asgi/venv/lib/python3.7/site-packages/starlette/websockets.py", line 116, in send_json
await self.send({"type": "websocket.send", "text": text})
File "/X/tartiflette-asgi/venv/lib/python3.7/site-packages/starlette/websockets.py", line 68, in send
await self._send(message)
File "/X/tartiflette-asgi/venv/lib/python3.7/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 218, in asgi_send
raise RuntimeError(msg % message_type)
RuntimeError: Unexpected ASGI message 'websocket.send', after sending 'websocket.close'.

@florimondmanca
Copy link
Contributor

Hi, thanks for reporting this!

Can you confirm this is what you did?

  1. Start the server.
  2. Access the GraphiQL interface in the browser.
  3. Hit "play" to start the timer.
  4. Before the timer ends, stop the server while the subscriptions is still running.

Or had the timer already finished on step 4?

@florimondmanca florimondmanca added the bug Something isn't working label Oct 8, 2019
@AutumnalDream
Copy link
Contributor Author

My bad. Was in the middle of writing this but had to run. Those steps are correct. I've been able to trigger that by shutting the server down in the middle of the subscription as well as hitting the play button again in the middle of the subscription running.

@florimondmanca
Copy link
Contributor

Thanks @AutumnalDream!

I think a good first step to resolving this would be to add a failing test case. Not sure yet how this can be reproduced programmatically, but I think the idea of "launching a new subscription seems to cancel the previous one and crash it" seems like a good starting point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants