daphne: KeyError from create_application
Since upgrading to Channels 2, I get a number of these errors. I suspect this happens when restarting the deployed instance:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/daphne/http_protocol.py", line 160, in process
"server": self.server_addr,
File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
result = g.send(result)
File "/usr/local/lib/python3.6/site-packages/daphne/server.py", line 191, in create_application
), loop=asyncio.get_event_loop())
KeyError: <WebRequest at 0x7ff738677710 method=GET uri=/api/internal/projects/21/managed_objects/ clientproto=HTTP/1.1>
Unfortunately, it doesn’t help that there is a lot happening on this line, and I am not sure what part causes this error.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 26 (21 by maintainers)
Commits related to this issue
- Don't try and read requests that are closed already (#205) — committed to django/daphne by deleted user 6 years ago
- Don't crash if connection closed before application started (#213) Fixes #205. — committed to django/daphne by brianmay 6 years ago
Reference to commit that (hopefully) fixed this: ece52b8e7958b41c86fd89830bc7814368e42bde
Twisted closes “content” when the connection is lost, i.e. request is “finished” internally in Twisted. I fixed it by checking
if self.content.closed:before initiating the request handling where content is read.Similar error only happened for me when using nginx as reverse proxy and I was able to reproduce it consistently when I found a working way to trigger it.