summary refs log tree commit diff
path: root/synapse/http
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2016-12-29 15:51:04 +0000
committerMark Haines <mark.haines@matrix.org>2016-12-29 15:51:04 +0000
commit97ffc5690b713b64556dc4d0993cf2a96f4477e8 (patch)
tree6c357cc676b07c401cb8c1191158a9af3bd9b264 /synapse/http
parentRespect long_retries param and default to off (diff)
downloadsynapse-97ffc5690b713b64556dc4d0993cf2a96f4477e8.tar.xz
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.
Diffstat (limited to '')
-rw-r--r--synapse/http/endpoint.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/synapse/http/endpoint.py b/synapse/http/endpoint.py
index 95424481ca..8c64339a7c 100644
--- a/synapse/http/endpoint.py
+++ b/synapse/http/endpoint.py
@@ -89,8 +89,8 @@ class _WrappingEndpointFac(object):
 
 
 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"]
 
@@ -107,20 +107,28 @@ class _WrappedConnection(object):
     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