Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the Issue of TCP not closing #480

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/databricks/sql/auth/thrift_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def close(self):
self.__resp and self.__resp.drain_conn()
self.__resp and self.__resp.release_conn()
self.__resp = None
self.__pool = None

def read(self, sz):
return self.__resp.read(sz)
Expand Down
7 changes: 6 additions & 1 deletion src/databricks/sql/thrift_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ def attempt_request(attempt):
# - non-None retry_delay -> sleep delay before retry
# - error, error_message always set when available

exception_occurred = False
error, error_message, retry_delay = None, None, None
try:
this_method_name = getattr(method, "__name__")
Expand All @@ -388,6 +389,7 @@ def attempt_request(attempt):
return response

except urllib3.exceptions.HTTPError as err:
exception_occurred = True
# retry on timeout. Happens a lot in Azure and it is safe as data has not been sent to server yet

# TODO: don't use exception handling for GOS polling...
Expand All @@ -406,6 +408,7 @@ def attempt_request(attempt):
else:
raise err
except OSError as err:
exception_occurred = True
error = err
error_message = str(err)
# fmt: off
Expand Down Expand Up @@ -436,12 +439,14 @@ def attempt_request(attempt):
else:
logger.warning(log_string)
except Exception as err:
exception_occurred = True
error = err
retry_delay = extract_retry_delay(attempt)
error_message = ThriftBackend._extract_error_message_from_headers(
getattr(self._transport, "headers", {})
)
finally:

if exception_occurred:
# Calling `close()` here releases the active HTTP connection back to the pool
self._transport.close()

Expand Down
Loading