-
Notifications
You must be signed in to change notification settings - Fork 721
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
due to select() paho-mqtt is unable to connect if more than 1024 file handle are used #819
Comments
If you really need 1000 threads I would strongly suggest a library with native async support, e.g.: |
That's a nice issue... pretty obscure to find the cause if you never see such issue. tl; dr: we should no longer use select() Here is how to reproduce the same issue you had with an every more strange code:
This will fail, the client will not be connected. To fix this code, just change the number 1019 in 1018 :) More seriously, the issue is:
This issue is that select (only on Linux ?) can't work with FD >= 1024
In your program, you should have about 340 connections working. Socket pair (as it name said) create 2 FDs. 340 * 3 (the MQTT socket & the two sockets of the socket pair) = 1020. Then add stdout, stdin and stderr -> 1023. The immediate fix is to don't use select() which means don't use loop(), loop_start() or loop_forever(). This mostly means use the external loop a.k.a an ayncio (either with a third-party that wrap it, or directly - there is some example). The right fix is to change paho so that it stop using select() and use modern solution (probably Python selectors). |
thanks,I will try! |
Can you provide me with some examples or other packages that can solve this problem? |
I'm not using paho-mqtt with asyncio, so I don't really know one. I've seen the name https://github.com/sbtinstruments/aiomqtt passed in another issue. |
Problem description:
Python version: 3.9
Paho-MQTT version: 1.6.1
When using 1000 threads, each thread as a client to connect to the MQTT service, due to the _socketpair_compat function in loop_start, only a few hundred clients can be connected, and all clients cannot be connected successfully.
After adjusting the system file handle number to 65535, it still fails to connect.
However, if the _socketpair_compat function is commented out, all clients can connect successfully.
Question:
Is there any way to solve this problem?
The text was updated successfully, but these errors were encountered: