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

Cleanup socket on connection error/timeout #346

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions pssh/clients/base/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,12 @@ def _connect_socket(self, family, _type, proto, sock_addr, host, port, retries):
try:
self.sock.connect(sock_addr)
except ConnectionRefusedError:
self.sock.shutdown(socket.SHUT_RDWR)
Copy link
Member

@pkittenis pkittenis Aug 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.sock.shutdown(socket.SHUT_RDWR)
if not self.sock.closed:
self.sock.shutdown(socket.SHUT_RDWR)
self.sock.close()

Otherwise will get test failures for already closed sockets - see test failures. Might also want to split the above block to an internal function, since same thing is needed below.

self.sock.close()
raise
except sock_error as ex:
self.sock.shutdown(socket.SHUT_RDWR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also needs a check that self.sock is not already closed - as above.

self.sock.close()
logger.error("Error connecting to host '%s:%s' - retry %s/%s",
host, port, retries, self.num_retries)
while retries < self.num_retries:
Expand Down