Skip to content

Commit

Permalink
Close socket explicitly (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
sitingren authored Feb 2, 2023
1 parent 11f95fe commit 760d25b
Showing 1 changed file with 20 additions and 13 deletions.
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

0 comments on commit 760d25b

Please sign in to comment.