Skip to content

Commit

Permalink
fix: websocket shutdown failure
Browse files Browse the repository at this point in the history
If a heartbeat timeout or connection failure occurs, the shutdown logic
was using original functionality (unwrap), which doesn't exist for
websocket. This internally caught except then put the thread in a bad
state where the consumer of the transport could not try to reconnect.

Signed-off-by: Mike Marchetti <mfmarche@gmail.com>
  • Loading branch information
mfmarche committed Nov 11, 2022
1 parent 4348785 commit fa0b9ba
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions stomp/adapter/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,27 +170,13 @@ def disconnect_socket(self):
"""
self.running = False
if self.socket is not None:
if self.__need_ssl():
#
# Even though we don't want to use the socket, unwrap is the only API method which does a proper SSL
# shutdown
#
try:
self.socket = self.socket.unwrap()
except Exception:
#
# unwrap seems flaky on Win with the back-ported ssl mod, so catch any exception and log it
#
_, e, _ = sys.exc_info()
logging.warning(e)
elif hasattr(socket, "SHUT_RDWR"):
try:
self.socket.shutdown(socket.SHUT_RDWR)
except socket.error:
_, e, _ = sys.exc_info()
# ignore when socket already closed
if get_errno(e) != errno.ENOTCONN:
logging.warning("Unable to issue SHUT_RDWR on socket because of error '%s'", e)
try:
self.socket.shutdown()
except socket.error:
_, e, _ = sys.exc_info()
# ignore when socket already closed
if get_errno(e) != errno.ENOTCONN:
logging.warning("Unable to issue SHUT_RDWR on socket because of error '%s'", e)

#
# split this into a separate check, because sometimes the socket is nulled between shutdown and this call
Expand Down

0 comments on commit fa0b9ba

Please sign in to comment.