Skip to content

recv_timeout should be used as a receive timeout in _sock_exact_recv() #189

Closed
@vladak

Description

@vladak

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:

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 ... MMQTTExceptions used throughout the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions