mirror of
https://github.com/django/daphne.git
synced 2024-11-21 23:46:33 +03:00
Don't crash if connection closed before application started (#213)
Fixes #205.
This commit is contained in:
parent
6dcc0d52b3
commit
d5611bccb6
|
@ -160,7 +160,7 @@ class WebRequest(http.Request):
|
|||
"server": self.server_addr,
|
||||
})
|
||||
# Check they didn't close an unfinished request
|
||||
if self.content.closed:
|
||||
if self.application_queue is None or self.content.closed:
|
||||
# Not much we can do, the request is prematurely abandoned.
|
||||
return
|
||||
# Run application against request
|
||||
|
|
|
@ -185,6 +185,8 @@ class Server(object):
|
|||
input_queue = asyncio.Queue()
|
||||
application_instance = yield deferToThread(self.application, scope=scope)
|
||||
# Run it, and stash the future for later checking
|
||||
if protocol not in self.connections:
|
||||
return None
|
||||
self.connections[protocol]["application_instance"] = asyncio.ensure_future(application_instance(
|
||||
receive=input_queue.get,
|
||||
send=lambda message: self.handle_reply(protocol, message),
|
||||
|
|
|
@ -75,8 +75,9 @@ class WebSocketProtocol(WebSocketServerProtocol):
|
|||
"server": self.server_addr,
|
||||
"subprotocols": subprotocols,
|
||||
})
|
||||
self.application_deferred.addCallback(self.applicationCreateWorked)
|
||||
self.application_deferred.addErrback(self.applicationCreateFailed)
|
||||
if self.application_deferred is not None:
|
||||
self.application_deferred.addCallback(self.applicationCreateWorked)
|
||||
self.application_deferred.addErrback(self.applicationCreateFailed)
|
||||
except Exception as e:
|
||||
# Exceptions here are not displayed right, just 500.
|
||||
# Turn them into an ERROR log.
|
||||
|
|
Loading…
Reference in New Issue
Block a user