Manually abort the underlying TLS connection.

The abort() method calls loseConnection() which tries to shutdown the
TLS connection cleanly. We now call abortConnection() directly which
should promptly close both the TLS connection and the underlying TCP
connection.

I also added some TODO markers to consider cancelling the old previous
timeout rather than checking time.time(). But given how urgently we want
to get this code released I'd rather leave the existing code with the
duplicate timeouts and the time.time() check.
pull/1725/head
Mark Haines 2016-12-29 15:51:04 +00:00
parent b4bc6fef5b
commit 97ffc5690b
1 changed files with 10 additions and 2 deletions

View File

@ -89,8 +89,8 @@ class _WrappingEndpointFac(object):
class _WrappedConnection(object): class _WrappedConnection(object):
"""Wraps a connection and calls abort on it if it hasn't seen any actio """Wraps a connection and calls abort on it if it hasn't seen any action
for 5 minutes for 2.5-3 minutes.
""" """
__slots__ = ["conn", "last_request"] __slots__ = ["conn", "last_request"]
@ -107,20 +107,28 @@ class _WrappedConnection(object):
def _time_things_out_maybe(self): def _time_things_out_maybe(self):
# We use a slightly shorter timeout here just in case the callLater is # We use a slightly shorter timeout here just in case the callLater is
# triggered early. Paranoia ftw. # triggered early. Paranoia ftw.
# TODO: Cancel the previous callLater rather than comparing time.time()?
if time.time() - self.last_request >= 2.5 * 60: if time.time() - self.last_request >= 2.5 * 60:
self.abort() self.abort()
# Abort the underlying TLS connection. The abort() method calls
# loseConnection() on the underlying TLS connection which tries to
# shutdown the connection cleanly. We call abortConnection()
# since that will promptly close the underlying TCP connection.
self.transport.abortConnection()
def request(self, request): def request(self, request):
self.last_request = time.time() self.last_request = time.time()
# Time this connection out if we haven't send a request in the last # Time this connection out if we haven't send a request in the last
# N minutes # N minutes
# TODO: Cancel the previous callLater?
reactor.callLater(3 * 60, self._time_things_out_maybe) reactor.callLater(3 * 60, self._time_things_out_maybe)
d = self.conn.request(request) d = self.conn.request(request)
def update_request_time(res): def update_request_time(res):
self.last_request = time.time() self.last_request = time.time()
# TODO: Cancel the previous callLater?
reactor.callLater(3 * 60, self._time_things_out_maybe) reactor.callLater(3 * 60, self._time_things_out_maybe)
return res return res