Skip to content

Commit

Permalink
Manually abort the underlying TLS connection.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mark Haines committed Dec 29, 2016
1 parent b4bc6fe commit 97ffc56
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions synapse/http/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def connect(self, protocolFactory):


class _WrappedConnection(object):
"""Wraps a connection and calls abort on it if it hasn't seen any actio
for 5 minutes
"""Wraps a connection and calls abort on it if it hasn't seen any action
for 2.5-3 minutes.
"""
__slots__ = ["conn", "last_request"]

Expand All @@ -107,20 +107,28 @@ def __setattr__(self, name, value):
def _time_things_out_maybe(self):
# We use a slightly shorter timeout here just in case the callLater is
# triggered early. Paranoia ftw.
# TODO: Cancel the previous callLater rather than comparing time.time()?
if time.time() - self.last_request >= 2.5 * 60:
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):
self.last_request = time.time()

# Time this connection out if we haven't send a request in the last
# N minutes
# TODO: Cancel the previous callLater?
reactor.callLater(3 * 60, self._time_things_out_maybe)

d = self.conn.request(request)

def update_request_time(res):
self.last_request = time.time()
# TODO: Cancel the previous callLater?
reactor.callLater(3 * 60, self._time_things_out_maybe)
return res

Expand Down

0 comments on commit 97ffc56

Please sign in to comment.