@@ -147,7 +147,7 @@ def addurl(text):
147147
148148 failures = 0
149149 error = None
150- while failures < _MAX_CONSECUTIVE_FAILS and not interrupted ():
150+ while failures <= _MAX_CONSECUTIVE_FAILS and not interrupted ():
151151 try :
152152 if __debug__ : log (addurl (f'doing http { method } ' ))
153153 func = getattr (client , method )
@@ -157,8 +157,6 @@ def addurl(text):
157157 if __debug__ : log (addurl (f'got response with code { code } ' ))
158158 if code not in [400 , 409 , 502 , 503 , 504 ] or failures > _MAX_CONSECUTIVE_FAILS :
159159 return response
160- else :
161- failures += 1
162160 except KeyboardInterrupt as ex :
163161 if __debug__ : log (addurl (f'network { method } interrupted by { antiformat (ex )} ' ))
164162 raise
@@ -188,19 +186,27 @@ def addurl(text):
188186 # about being unable to reconnect and not the original problem.
189187 if not error :
190188 error = ex
189+ # If there's response text, it may contain diagnostic info.
190+ if __debug__ :
191+ text = response .text [:500 ] + (' ...' if len (response .text ) > 500 else '' )
192+ log ('response text: ' + text )
191193 if failures == 0 :
192194 # Pause briefly b/c it's rarely a good idea to retry immediately.
193195 if __debug__ : log (addurl ('pausing briefly before retrying' ))
194196 wait (0.5 )
195197 failures += 1
196- elif failures <= _MAX_CONSECUTIVE_FAILS :
198+ elif failures < _MAX_CONSECUTIVE_FAILS :
197199 # Pause with exponential back-off, reset failure count & try again.
198- pause = 10 * failures * failures
200+ pause = 5 * failures * failures
199201 if __debug__ : log (addurl ('pausing due to consecutive failures' ))
200202 wait (pause )
203+ failures += 1
201204 else :
202205 if __debug__ : log (addurl ('exceeded max failures' ))
203- raise error
206+ if error :
207+ raise error
208+ else :
209+ return response
204210 if interrupted ():
205211 if __debug__ : log (addurl ('interrupted' ))
206212 raise Interrupted (addurl ('Network request has been interrupted' ))
0 commit comments