Skip to content

Commit d905b5d

Browse files
committed
Simplify socket connect retry logic
1 parent d56df20 commit d905b5d

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@
3535
import time
3636
from random import randint
3737

38-
from adafruit_connection_manager import (
39-
get_connection_manager,
40-
SocketGetOSError,
41-
SocketConnectMemoryError,
42-
)
38+
from adafruit_connection_manager import get_connection_manager
4339

4440
try:
4541
from typing import List, Optional, Tuple, Type, Union
@@ -87,8 +83,6 @@
8783
_default_sock = None # pylint: disable=invalid-name
8884
_fake_context = None # pylint: disable=invalid-name
8985

90-
TemporaryError = (SocketGetOSError, SocketConnectMemoryError)
91-
9286

9387
class MMQTTException(Exception):
9488
"""MiniMQTT Exception class."""
@@ -430,8 +424,8 @@ def connect(
430424
)
431425
self._reset_reconnect_backoff()
432426
return ret
433-
except TemporaryError as e:
434-
self.logger.warning(f"temporary error when connecting: {e}")
427+
except RuntimeError as e:
428+
self.logger.warning(f"Socket error when connecting: {e}")
435429
backoff = False
436430
except MMQTTException as e:
437431
last_exception = e
@@ -486,8 +480,6 @@ def _connect(
486480
timeout=self._socket_timeout,
487481
is_ssl=self._is_ssl,
488482
ssl_context=self._ssl_context,
489-
max_retries=1, # setting to 1 since we want to handle backoff internally
490-
exception_passthrough=True,
491483
)
492484

493485
fixed_header = bytearray([0x10])

tests/test_port_ssl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test_tls_without_ssl_context(self) -> None:
116116
connect_retries=1,
117117
)
118118

119-
with self.assertRaises(RuntimeError) as context:
119+
with self.assertRaises(AttributeError) as context:
120120
mqtt_client.connect()
121121
self.assertTrue("ssl_context must be set" in str(context))
122122

0 commit comments

Comments
 (0)