Skip to content

make connect retries configurable #119

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

Merged
merged 2 commits into from
Aug 31, 2022
Merged
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
5 changes: 4 additions & 1 deletion adafruit_minimqtt/adafruit_minimqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class MQTT:
:param bool use_binary_mode: Messages are passed as bytearray instead of string to callbacks.
:param int socket_timeout: How often to check socket state for read/write/connect operations,
in seconds.
:param int connect_retries: How many times to try to connect to broker before giving up.

"""

Expand All @@ -152,6 +153,7 @@ def __init__(
ssl_context=None,
use_binary_mode=False,
socket_timeout=1,
connect_retries=5,
):

self._socket_pool = socket_pool
Expand All @@ -166,6 +168,7 @@ def __init__(
)
self._socket_timeout = socket_timeout
self._recv_timeout = recv_timeout
self._connect_retries = connect_retries

self.keep_alive = keep_alive
self._user_data = None
Expand Down Expand Up @@ -267,7 +270,7 @@ def _get_connect_socket(self, host, port, *, timeout=1):
sock = None
retry_count = 0
last_exception = None
while retry_count < 5 and sock is None:
while retry_count < self._connect_retries and sock is None:
retry_count += 1

try:
Expand Down