Skip to content
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

Handle edge case where socket is None #686

Merged

Conversation

RobertDeRose
Copy link
Contributor

  • 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.

Fixes #505

@RobertDeRose
Copy link
Contributor Author

@ralight I've search the issues and see others have reports this issue and stated that calling loop_start instead of loop_forver, however, loop_start just calls loop_forever on its own and this issue can happen and its not possible to catch it as it's inside an unmanaged thread.

This might not be to the correct fix, but it fixes it for me and I would assume others as if the Socket is None, there is no connection and the reconnect logic seems to kick in

@RobertDeRose
Copy link
Contributor Author

@ralight and @PierreF hate to be a bother here, but this is causing me some headaches in a production environment and while I could make a fork and build my own version, It would be nice if one of the maintainers could confirm that this appears to be the correct fix. Thanks!

@RobertDeRose RobertDeRose force-pushed the bugfix/handle-attribute-error-on-connect branch from 169edce to b66d28c Compare November 29, 2022 16:43
* 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 <RobertDeRose@gmail.com>
@RobertDeRose RobertDeRose force-pushed the bugfix/handle-attribute-error-on-connect branch from 7fb6936 to 2338d27 Compare November 29, 2022 20:25
@gabrielgbs97
Copy link

Would like to see this one on main, had same issue... Still couldn't face the root of cause

@RobertDeRose
Copy link
Contributor Author

@gabrielgbs97

I gave up getting this PR merged. I ended up doing my own thread management

Just start your own thread, call loop_forver inside a try..except block and recall loop_fover if an exception is thrown
The thread is simple a while True: around the try...except

@lucasjinreal
Copy link

@ralight Please merge this PR, this caused seriously randomly issues in our production!

@@ -1,4 +1,4 @@
__version__ = "1.6.1"
__version__ = "1.6.2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not change the version in a PR

@PierreF PierreF merged commit 590f793 into eclipse:master Dec 23, 2023
5 checks passed
@PierreF
Copy link
Contributor

PierreF commented Dec 23, 2023

Thank for your contribution.

As I said in #505, I think the real fix would be to audit concurrency access and improve either locking or improve documentation on what could be called concurrently. In the meantime your fix seems simple and correct the the described problem.

@RobertDeRose RobertDeRose deleted the bugfix/handle-attribute-error-on-connect branch December 26, 2023 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AttributeError: 'NoneType' object has no attribute 'recv'
4 participants