Skip to content

Commit a477dc8

Browse files
committed
Fixed the Issue of TCP not closing
1 parent 680b3b6 commit a477dc8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/databricks/sql/auth/thrift_http_client.py

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def close(self):
144144
self.__resp and self.__resp.drain_conn()
145145
self.__resp and self.__resp.release_conn()
146146
self.__resp = None
147+
self.__pool = None
147148

148149
def read(self, sz):
149150
return self.__resp.read(sz)

src/databricks/sql/thrift_backend.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)