Skip to content

Commit

Permalink
Cancel old keepalive-trigger before setting new one. (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdeler authored Oct 26, 2020
1 parent ef80625 commit d5dcf80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion uvicorn/protocols/http/h11_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,14 @@ def connection_lost(self, exc):
def eof_received(self):
pass

def data_received(self, data):
def _unset_keepalive_if_required(self):
if self.timeout_keep_alive_task is not None:
self.timeout_keep_alive_task.cancel()
self.timeout_keep_alive_task = None

def data_received(self, data):
self._unset_keepalive_if_required()

self.conn.receive_data(data)
self.handle_events()

Expand Down Expand Up @@ -299,6 +302,8 @@ def on_response_complete(self):
return

# Set a short Keep-Alive timeout.
self._unset_keepalive_if_required()

self.timeout_keep_alive_task = self.loop.call_later(
self.timeout_keep_alive, self.timeout_keep_alive_handler
)
Expand Down
7 changes: 6 additions & 1 deletion uvicorn/protocols/http/httptools_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,14 @@ def connection_lost(self, exc):
def eof_received(self):
pass

def data_received(self, data):
def _unset_keepalive_if_required(self):
if self.timeout_keep_alive_task is not None:
self.timeout_keep_alive_task.cancel()
self.timeout_keep_alive_task = None

def data_received(self, data):
self._unset_keepalive_if_required()

try:
self.parser.feed_data(data)
except httptools.HttpParserError:
Expand Down Expand Up @@ -301,6 +304,8 @@ def on_response_complete(self):
return

# Set a short Keep-Alive timeout.
self._unset_keepalive_if_required()

self.timeout_keep_alive_task = self.loop.call_later(
self.timeout_keep_alive, self.timeout_keep_alive_handler
)
Expand Down

0 comments on commit d5dcf80

Please sign in to comment.