-
Notifications
You must be signed in to change notification settings - Fork 51
Description
socket_timeout
is period which the underlying implementation will break out from a "select" loop, "recv_timeout" should be the maximum period for which to wait for data from the server. _sock_exact_recv()
however uses keep_alive
as a receive timeout:
Adafruit_CircuitPython_MiniMQTT/adafruit_minimqtt/adafruit_minimqtt.py
Lines 1118 to 1127 in 1c25441
read_timeout = self.keep_alive | |
mv = mv[recv_len:] | |
while to_read > 0: | |
recv_len = self._sock.recv_into(mv, to_read) | |
to_read -= recv_len | |
mv = mv[recv_len:] | |
if time.monotonic() - stamp > read_timeout: | |
raise MMQTTException( | |
f"Unable to receive {to_read} bytes within {read_timeout} seconds." | |
) |
By default socket_timeout
is 1 second, recv_timeout
is 10 seconds and keep_alive
is 60 seconds.
As a result, when a server disconnects the client and the client pings it, it will take 60 seconds for the client to discover that the connection is unresponsive. Instead, recv_timeout
should be used. The way I understand it is that keep alive is server side feature and should not trump receive timeout on the client.
The fix would simplify the various No data ...
MMQTTException
s used throughout the code.