diff --git a/aiohttp/server.py b/aiohttp/server.py index 9d467e47293..b3f4ac17c61 100644 --- a/aiohttp/server.py +++ b/aiohttp/server.py @@ -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 @@ -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) @@ -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) @@ -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) @@ -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