@@ -365,6 +365,7 @@ def attempt_request(attempt):
365365 # - non-None retry_delay -> sleep delay before retry
366366 # - error, error_message always set when available
367367
368+ exception_occurred = False
368369 error , error_message , retry_delay = None , None , None
369370 try :
370371 this_method_name = getattr (method , "__name__" )
@@ -388,6 +389,7 @@ def attempt_request(attempt):
388389 return response
389390
390391 except urllib3 .exceptions .HTTPError as err :
392+ exception_occurred = True
391393 # retry on timeout. Happens a lot in Azure and it is safe as data has not been sent to server yet
392394
393395 # TODO: don't use exception handling for GOS polling...
@@ -406,6 +408,7 @@ def attempt_request(attempt):
406408 else :
407409 raise err
408410 except OSError as err :
411+ exception_occurred = True
409412 error = err
410413 error_message = str (err )
411414 # fmt: off
@@ -436,12 +439,14 @@ def attempt_request(attempt):
436439 else :
437440 logger .warning (log_string )
438441 except Exception as err :
442+ exception_occurred = True
439443 error = err
440444 retry_delay = extract_retry_delay (attempt )
441445 error_message = ThriftBackend ._extract_error_message_from_headers (
442446 getattr (self ._transport , "headers" , {})
443447 )
444- finally :
448+
449+ if exception_occurred :
445450 # Calling `close()` here releases the active HTTP connection back to the pool
446451 self ._transport .close ()
447452
0 commit comments