@@ -365,6 +365,7 @@ def attempt_request(attempt):
365
365
# - non-None retry_delay -> sleep delay before retry
366
366
# - error, error_message always set when available
367
367
368
+ exception_occurred = False
368
369
error , error_message , retry_delay = None , None , None
369
370
try :
370
371
this_method_name = getattr (method , "__name__" )
@@ -388,6 +389,7 @@ def attempt_request(attempt):
388
389
return response
389
390
390
391
except urllib3 .exceptions .HTTPError as err :
392
+ exception_occurred = True
391
393
# retry on timeout. Happens a lot in Azure and it is safe as data has not been sent to server yet
392
394
393
395
# TODO: don't use exception handling for GOS polling...
@@ -406,6 +408,7 @@ def attempt_request(attempt):
406
408
else :
407
409
raise err
408
410
except OSError as err :
411
+ exception_occurred = True
409
412
error = err
410
413
error_message = str (err )
411
414
# fmt: off
@@ -436,12 +439,14 @@ def attempt_request(attempt):
436
439
else :
437
440
logger .warning (log_string )
438
441
except Exception as err :
442
+ exception_occurred = True
439
443
error = err
440
444
retry_delay = extract_retry_delay (attempt )
441
445
error_message = ThriftBackend ._extract_error_message_from_headers (
442
446
getattr (self ._transport , "headers" , {})
443
447
)
444
- finally :
448
+
449
+ if exception_occurred :
445
450
# Calling `close()` here releases the active HTTP connection back to the pool
446
451
self ._transport .close ()
447
452
0 commit comments