5656)
5757
5858
59- MAX_RETRIES = 10
59+ MAX_LONG_RETRIES = 10
60+ MAX_SHORT_RETRIES = 3
6061
6162
6263class MatrixFederationEndpointFactory (object ):
@@ -103,7 +104,7 @@ def _create_url(self, destination, path_bytes, param_bytes, query_bytes):
103104 def _create_request (self , destination , method , path_bytes ,
104105 body_callback , headers_dict = {}, param_bytes = b"" ,
105106 query_bytes = b"" , retry_on_dns_fail = True ,
106- timeout = None ):
107+ timeout = None , long_retries = False ):
107108 """ Creates and sends a request to the given url
108109 """
109110 headers_dict [b"User-Agent" ] = [self .version_string ]
@@ -123,7 +124,10 @@ def _create_request(self, destination, method, path_bytes,
123124
124125 # XXX: Would be much nicer to retry only at the transaction-layer
125126 # (once we have reliable transactions in place)
126- retries_left = MAX_RETRIES
127+ if long_retries :
128+ retries_left = MAX_LONG_RETRIES
129+ else :
130+ retries_left = MAX_SHORT_RETRIES
127131
128132 http_url_bytes = urlparse .urlunparse (
129133 ("" , "" , path_bytes , param_bytes , query_bytes , "" )
@@ -184,9 +188,15 @@ def send_request():
184188 )
185189
186190 if retries_left and not timeout :
187- delay = 4 ** (MAX_RETRIES + 1 - retries_left )
188- delay = max (delay , 60 )
189- delay *= random .uniform (0.8 , 1.4 )
191+ if long_retries :
192+ delay = 4 ** (MAX_LONG_RETRIES + 1 - retries_left )
193+ delay = max (delay , 60 )
194+ delay *= random .uniform (0.8 , 1.4 )
195+ else :
196+ delay = 0.5 * 2 ** (MAX_SHORT_RETRIES - retries_left )
197+ delay = max (delay , 2 )
198+ delay *= random .uniform (0.8 , 1.4 )
199+
190200 yield sleep (delay )
191201 retries_left -= 1
192202 else :
@@ -237,7 +247,8 @@ def sign_request(self, destination, method, url_bytes, headers_dict,
237247 headers_dict [b"Authorization" ] = auth_headers
238248
239249 @defer .inlineCallbacks
240- def put_json (self , destination , path , data = {}, json_data_callback = None ):
250+ def put_json (self , destination , path , data = {}, json_data_callback = None ,
251+ long_retries = False ):
241252 """ Sends the specifed json data using PUT
242253
243254 Args:
@@ -248,6 +259,8 @@ def put_json(self, destination, path, data={}, json_data_callback=None):
248259 the request body. This will be encoded as JSON.
249260 json_data_callback (callable): A callable returning the dict to
250261 use as the request body.
262+ long_retries (bool): A boolean that indicates whether we should
263+ retry for a short or long time.
251264
252265 Returns:
253266 Deferred: Succeeds when we get a 2xx HTTP response. The result
@@ -273,6 +286,7 @@ def body_callback(method, url_bytes, headers_dict):
273286 path .encode ("ascii" ),
274287 body_callback = body_callback ,
275288 headers_dict = {"Content-Type" : ["application/json" ]},
289+ long_retries = long_retries ,
276290 )
277291
278292 if 200 <= response .code < 300 :
@@ -491,6 +505,9 @@ def pauseProducing(self):
491505 def stopProducing (self ):
492506 pass
493507
508+ def resumeProducing (self ):
509+ pass
510+
494511
495512def _flatten_response_never_received (e ):
496513 if hasattr (e , "reasons" ):
0 commit comments