Skip to content

Commit

Permalink
Handle edge case where socket is None (#686)
Browse files Browse the repository at this point in the history
* Handle edge case where socket is None

* The following exception happens randomly on startup:

```
Exception has occurred: AttributeError
'NoneType' object has no attribute 'recv'
File "paho/mqtt/client.py", line 640, in _sock_recv
```

* The root cause is unknown, but this allows the library to reconnect
  gracefully.

Signed-off-by: Robert DeRose <[email protected]>
  • Loading branch information
RobertDeRose authored Dec 23, 2023
1 parent 6ba3ff0 commit 590f793
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/paho/mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@ def _sock_recv(self, bufsize):
except ssl.SSLWantWriteError:
self._call_socket_register_write()
raise BlockingIOError
except AttributeError as err:
self._easy_log(
MQTT_LOG_DEBUG, "socket was None: %s", err)
raise ConnectionError

def _sock_send(self, buf):
try:
Expand Down

0 comments on commit 590f793

Please sign in to comment.