Skip to content

Commit

Permalink
Merge pull request #224 from rbedia/socket-handling
Browse files Browse the repository at this point in the history
Close the socket when there is an error using the socket
  • Loading branch information
tannewt authored Oct 9, 2024
2 parents 25a9218 + 8595e36 commit 62abc1a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion adafruit_minimqtt/adafruit_minimqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ def connect(
except (MemoryError, OSError, RuntimeError) as e:
if isinstance(e, RuntimeError) and e.args == ("pystack exhausted",):
raise
self._close_socket()
self.logger.warning(f"Socket error when connecting: {e}")
last_exception = e
backoff = False
Expand Down Expand Up @@ -591,7 +592,7 @@ def disconnect(self) -> None:
self.logger.debug("Sending DISCONNECT packet to broker")
try:
self._sock.send(MQTT_DISCONNECT)
except RuntimeError as e:
except (MemoryError, OSError, RuntimeError) as e:
self.logger.warning(f"Unable to send DISCONNECT packet: {e}")
self._close_socket()
self._is_connected = False
Expand Down

0 comments on commit 62abc1a

Please sign in to comment.