Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

timeouts 2: electric boogaloo #3872

Merged
merged 8 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog.d/3872.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable buffering and automatic retrying in treq requests to prevent timeouts.
4 changes: 2 additions & 2 deletions synapse/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ def cancelled_to_request_timed_out_error(value, timeout):
return value


ACCESS_TOKEN_RE = re.compile(br'(\?.*access(_|%5[Ff])token=)[^&]*(.*)$')
ACCESS_TOKEN_RE = re.compile(r'(\?.*access(_|%5[Ff])token=)[^&]*(.*)$')


def redact_uri(uri):
"""Strips access tokens from the uri replaces with <redacted>"""
return ACCESS_TOKEN_RE.sub(
br'\1<redacted>\3',
r'\1<redacted>\3',
uri
)
6 changes: 3 additions & 3 deletions synapse/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def request(self, method, uri, data=b'', headers=None):
outgoing_requests_counter.labels(method).inc()

# log request but strip `access_token` (AS requests for example include this)
logger.info("Sending request %s %s", method, redact_uri(uri.encode('ascii')))
logger.info("Sending request %s %s", method, redact_uri(uri))

try:
request_deferred = treq.request(
Expand All @@ -108,14 +108,14 @@ def request(self, method, uri, data=b'', headers=None):
incoming_responses_counter.labels(method, response.code).inc()
logger.info(
"Received response to %s %s: %s",
method, redact_uri(uri.encode('ascii')), response.code
method, redact_uri(uri), response.code
)
defer.returnValue(response)
except Exception as e:
incoming_responses_counter.labels(method, "ERR").inc()
logger.info(
"Error sending request to %s %s: %s %s",
method, redact_uri(uri.encode('ascii')), type(e).__name__, e.args[0]
method, redact_uri(uri), type(e).__name__, e.args[0]
)
raise

Expand Down
4 changes: 3 additions & 1 deletion synapse/http/matrixfederationclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(self, hs):
self.server_name = hs.hostname
reactor = hs.get_reactor()
pool = HTTPConnectionPool(reactor)
pool.retryAutomatically = False
pool.maxPersistentPerHost = 5
pool.cachedConnectionTimeout = 2 * 60
self.agent = Agent.usingEndpointFactory(
Expand Down Expand Up @@ -221,7 +222,8 @@ def _request(self, destination, method, path,
headers=Headers(headers_dict),
data=data,
agent=self.agent,
reactor=self.hs.get_reactor()
reactor=self.hs.get_reactor(),
unbuffered=True
)
request_deferred.addTimeout(_sec_timeout, self.hs.get_reactor())
response = yield make_deferred_yieldable(
Expand Down
5 changes: 4 additions & 1 deletion synapse/http/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ def get_request_id(self):
return "%s-%i" % (self.method, self.request_seq)

def get_redacted_uri(self):
return redact_uri(self.uri)
uri = self.uri
if isinstance(uri, bytes):
uri = self.uri.decode('ascii')
return redact_uri(uri)

def get_user_agent(self):
return self.requestHeaders.getRawHeaders(b"User-Agent", [None])[-1]
Expand Down