Skip to content

Commit

Permalink
Write to transport rn before closing after keepalive timeout #1883
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed May 12, 2017
1 parent 0c78c32 commit d701f80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGES.rst
Expand Up @@ -5,7 +5,12 @@ Changes
2.1.0 (2017-xx-xx)
------------------

- Only call `loop.close` in `run_app` if the user did *not* supply a loop. Useful for allowing clients to specify their own cleanup before closing the asyncio loop if they wish to tightly control loop behavior
- Write to transport "\r\n" before closing after keepalive timeout,
otherwise client can not detect socket disconnection. #1883

- Only call `loop.close` in `run_app` if the user did *not* supply a loop.
Useful for allowing clients to specify their own cleanup before closing the
asyncio loop if they wish to tightly control loop behavior

- Content disposition with semicolon in filename #917

Expand Down
7 changes: 5 additions & 2 deletions aiohttp/web_protocol.py
Expand Up @@ -268,6 +268,7 @@ def eof_received(self):
pass

def data_received(self, data):
print("data:", data)
if self._force_close or self._close:
return

Expand Down Expand Up @@ -336,13 +337,15 @@ def close(self):
if not waiter.done():
waiter.cancel()

def force_close(self):
def force_close(self, keepalive=False):
"""Force close connection"""
self._force_close = True
for waiter in self._waiters:
if not waiter.done():
waiter.cancel()
if self.transport is not None:
if keepalive:
self.transport.write(b"\r\n")
self.transport.close()
self.transport = None

Expand All @@ -368,7 +371,7 @@ def _process_keepalive(self):
if len(self._request_handlers) == len(self._waiters):
now = self._time_service.loop_time
if now + 1.0 > next:
self.force_close()
self.force_close(keepalive=True)
return

self._keepalive_handle = self._loop.call_at(
Expand Down

0 comments on commit d701f80

Please sign in to comment.