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

Ceil server timeouts #702

Merged
merged 1 commit into from
Dec 22, 2015
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
22 changes: 14 additions & 8 deletions aiohttp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import socket

from html import escape as html_escape
from math import ceil

import aiohttp
from aiohttp import errors, streams, hdrs, helpers
Expand Down Expand Up @@ -136,8 +137,9 @@ def closing(self, timeout=15.0):

# use slow request timeout for closing
# connection_lost cleans timeout handler
self._timeout_handle = self._loop.call_later(
timeout, self.cancel_slow_request)
now = self._loop.time()
self._timeout_handle = self._loop.call_at(
ceil(now+timeout), self.cancel_slow_request)

def connection_made(self, transport):
super().connection_made(transport)
Expand All @@ -146,8 +148,9 @@ def connection_made(self, transport):

# start slow request timer
if self._timeout:
self._timeout_handle = self._loop.call_later(
self._timeout, self.cancel_slow_request)
now = self._loop.time()
self._timeout_handle = self._loop.call_at(
ceil(now+self._timeout), self.cancel_slow_request)

if self._keep_alive_on:
tcp_keepalive(self, transport)
Expand Down Expand Up @@ -235,8 +238,9 @@ def start(self):

# start slow request timer
if self._timeout and self._timeout_handle is None:
self._timeout_handle = self._loop.call_later(
self._timeout, self.cancel_slow_request)
now = self._loop.time()
self._timeout_handle = self._loop.call_at(
ceil(now+self._timeout), self.cancel_slow_request)

# read request headers
httpstream = reader.set_parser(self._request_parser)
Expand Down Expand Up @@ -295,8 +299,10 @@ def start(self):
self.log_debug(
'Start keep-alive timer for %s sec.',
self._keep_alive_period)
self._keep_alive_handle = self._loop.call_later(
self._keep_alive_period, self.transport.close)
now = self._loop.time()
self._keep_alive_handle = self._loop.call_at(
ceil(now+self._keep_alive_period),
self.transport.close)
elif self._keep_alive and self._keep_alive_on:
# do nothing, rely on kernel or upstream server
pass
Expand Down