paho.mqtt.python icon indicating copy to clipboard operation
paho.mqtt.python copied to clipboard

TimeoutError not handled

Open mlhales opened this issue 7 years ago • 2 comments

https://github.com/eclipse/paho.mqtt.python/blob/e9914a759f9f5b8081d59fd65edfd18d229a399e/src/paho/mqtt/client.py#L1470

When the client is connected using connect_async() and then loop_start() is called which runs loop_forever() in its own thread. The socket connection which happens in reconnect() can throw a TimeoutError which is not not caught, and cannot be caught by user code since the thread is owned by the library.

This can be fixed by catching socket.timeout in addition to socket.error, or by catching OSError.

socket.error is documented as a deprecated alias for OSError, but it does not seem to include TimeoutError which is a subclass of OSError

mlhales avatar Apr 10 '18 16:04 mlhales

It looks like this has been resolved in #291, so should this issue be closed as fixed in the v1.4.0 release?

ncoghlan avatar Aug 19 '19 06:08 ncoghlan

I'm having the same problem, but during _packet_read.

https://github.com/eclipse/paho.mqtt.python/blob/9782ab81fe7ee3a05e74c7f3e1d03d5611ea4be4/src/paho/mqtt/client.py#L2369-L2376 self._sock_recv(1) is raising a TimeoutError ([Errno 60] Operation timed out) and the thread created by loop_start crashes (without recovering). Is this an issue of the library, or should it be handled on an upper level?

EDIT: I'm using TCP sockets.

prsousa avatar Jan 05 '22 10:01 prsousa

I'm going to close this because the original issue appears to have been resolved (and there is a separate issue, #694, which looks like a better place to discuss the related issue in the comment from @prsousa). This is part of a general project to clean-up issues (which should make it simpler to identify priorities going forward).

MattBrittan avatar Dec 07 '23 21:12 MattBrittan