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,
|
"server": self.server_addr,
|
||||||
})
|
})
|
||||||
# Check they didn't close an unfinished request
|
# 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.
|
# Not much we can do, the request is prematurely abandoned.
|
||||||
return
|
return
|
||||||
# Run application against request
|
# Run application against request
|
||||||
|
|
|
@ -185,6 +185,8 @@ class Server(object):
|
||||||
input_queue = asyncio.Queue()
|
input_queue = asyncio.Queue()
|
||||||
application_instance = yield deferToThread(self.application, scope=scope)
|
application_instance = yield deferToThread(self.application, scope=scope)
|
||||||
# Run it, and stash the future for later checking
|
# 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(
|
self.connections[protocol]["application_instance"] = asyncio.ensure_future(application_instance(
|
||||||
receive=input_queue.get,
|
receive=input_queue.get,
|
||||||
send=lambda message: self.handle_reply(protocol, message),
|
send=lambda message: self.handle_reply(protocol, message),
|
||||||
|
|
|
@ -75,6 +75,7 @@ class WebSocketProtocol(WebSocketServerProtocol):
|
||||||
"server": self.server_addr,
|
"server": self.server_addr,
|
||||||
"subprotocols": subprotocols,
|
"subprotocols": subprotocols,
|
||||||
})
|
})
|
||||||
|
if self.application_deferred is not None:
|
||||||
self.application_deferred.addCallback(self.applicationCreateWorked)
|
self.application_deferred.addCallback(self.applicationCreateWorked)
|
||||||
self.application_deferred.addErrback(self.applicationCreateFailed)
|
self.application_deferred.addErrback(self.applicationCreateFailed)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user