Skip to content

Commit a4e2e20

Browse files
committed
improved http error/timeout handling
1 parent 57155ff commit a4e2e20

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

elmclient/httpops.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,22 +513,30 @@ def execute( self, no_error_log=False, close=False, **kwargs ):
513513

514514
# execute the request, retrying with increasing delays (login isn't handled at this level but at lower level)
515515
def _execute_request( self, *, no_error_log=False, close=False, cacheable=True, **kwargs ):
516-
for wait_dur in [2, 5, 10, 0]:
516+
for wait_dur in [2, 5, 10, 20, 30, 60, 0]:
517517
try:
518518
if not self._session.alwayscache and not cacheable:
519519
# add a header so the response isn't cached
520520
self._req.headers['Cache-Control'] = "no-store, max-age=0"
521521
result = self._execute_one_request_with_login( no_error_log=no_error_log, close=close, **kwargs)
522522
return result
523523
except requests.RequestException as e:
524-
if wait_dur == 0 or not self._is_retryable_error(e):
524+
# ALWAYS retry until all retry delays have been tried, the raise
525+
# logger.info( f"Got error on HTTP request. URL: {self._req.url}, {e.response.status_code}, {e.response.text}")
526+
logger.exception( f"Httpops RequestException was thrown for URL: {self._req.url} exception: {repr(e)}" )
527+
if wait_dur == 0
528+
logger.error( "HTTPOPS not succeeded after all timeouts! - giving up!"
525529
raise
526-
logger.info( f"Got error on HTTP request. URL: {self._req.url}, {e.response.status_code}, {e.response.text}")
527-
logger.warning( f'RETRY: Retry after {wait_dur} seconds... URL: {self._req.url}' )
530+
logger.error( f"HTTPOPS pausing for {wait_dur} then retrying"
528531
time.sleep(wait_dur)
532+
except: Exception as e:
533+
logger.exception( f"Unexpected exception was thrown for URL: {self._req.url}" )
534+
raise
535+
529536
raise Exception('programming error this point should never be reached')
530537

531-
# log a request/response, which may be the result of one or more redirections, so first log each of their request/response
538+
539+
logger.error( "HTTPOPS not succeeded after all timeouts! - giving up!" # log a request/response, which may be the result of one or more redirections, so first log each of their request/response
532540
def log_redirection_history( self, response, intent, action=None, donotlogbody=False ):
533541
thisintent = intent
534542
after = ""
@@ -673,6 +681,8 @@ def _log_response( self, response, action=None ):
673681
# categorize a Requests .send() exception e as to whether is retriable
674682
def _is_retryable_error( self, e ):
675683
if self._session.auto_retry:
684+
if e.response is None:
685+
return True
676686
if e.response.status_code in [
677687
http.client.REQUEST_TIMEOUT,
678688
http.client.LOCKED,

0 commit comments

Comments
 (0)