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

Only set disconnected time when it is not already set. #237

Merged
merged 5 commits into from
Nov 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions daphne/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ def protocol_connected(self, protocol):

def protocol_disconnected(self, protocol):
# Set its disconnected time (the loops will come and clean it up)
self.connections[protocol]["disconnected"] = time.time()
# Do not set it if it is already set. Overwriting it might
# cause it to never be cleaned up.
# See https://github.com/django/channels/issues/1181
if "disconnected" not in self.connections[protocol]:
self.connections[protocol]["disconnected"] = time.time()

### Internal event/message handling

Expand Down Expand Up @@ -208,8 +212,10 @@ async def handle_reply(self, protocol, message):
"""
Coroutine that jumps the reply message from asyncio to Twisted
"""
# Don't do anything if the connection is closed
if self.connections[protocol].get("disconnected", None):
# Don't do anything if the connection is closed or does not exist
if protocol not in self.connections or self.connections[protocol].get(
"disconnected", None
):
return
self.check_headers_type(message)
# Let the protocol handle it
Expand Down