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

Close socket explicitly #487

Merged
merged 1 commit into from
Feb 2, 2023
Merged
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
33 changes: 20 additions & 13 deletions vertica_python/vertica/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,21 +447,27 @@ def _socket(self):
if self.socket:
return self.socket

# the initial establishment of the client connection
# the initial establishment of the socket connection
raw_socket = self.establish_socket_connection(self.address_list)

# enable load balancing
load_balance_options = self.options.get('connection_load_balance')
self._logger.debug('Connection load balance option is {0}'.format(
'enabled' if load_balance_options else 'disabled'))
if load_balance_options:
raw_socket = self.balance_load(raw_socket)

# enable SSL
ssl_options = self.options.get('ssl')
self._logger.debug('SSL option is {0}'.format('enabled' if ssl_options else 'disabled'))
if ssl_options:
raw_socket = self.enable_ssl(raw_socket, ssl_options)
# modify the socket connection based on client connection options
try:
# enable load balancing
load_balance_options = self.options.get('connection_load_balance')
self._logger.debug('Connection load balance option is {0}'.format(
'enabled' if load_balance_options else 'disabled'))
if load_balance_options:
raw_socket = self.balance_load(raw_socket)

# enable SSL
ssl_options = self.options.get('ssl')
self._logger.debug('SSL option is {0}'.format('enabled' if ssl_options else 'disabled'))
if ssl_options:
raw_socket = self.enable_ssl(raw_socket, ssl_options)
except:
self._logger.debug('Close the socket')
raw_socket.close()
raise

self.socket = raw_socket
return self.socket
Expand Down Expand Up @@ -610,6 +616,7 @@ def write(self, message, vsocket=None):
raise

def close_socket(self):
self._logger.debug("Close connection's socket")
try:
if self.socket is not None:
self._socket().close()
Expand Down