-
Notifications
You must be signed in to change notification settings - Fork 986
client.close does not close the connection #2617
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
Comments
The sequence of calls looks ok. As you can see in the pymodbus code, close() calls the asyncio close, so that seems correct. I have not heard of problems with asyncio not closing sockets. It is known that some OS keep the socket active for a while, basically until the OS runs the central cleanup process...so maybe your problem is there. However you must be opening a lot of connections to make this happens (or have a very limited OS). One of my raspberry pi have 100+ connect active, and when testing on my mac mini I use 2.000+ connections. |
there are about 240 modbus devices and there is also bacnet and thermo devices via mqtt. I don't have this problem with MQTT and Bacnet. I can only see that the connections are kept open as you have described. but with each run I have twice as many connections, so I am very quickly over 2000 connections. At some point it just comes to an end. I'm still looking to see if it's debian problem. |
When you say "with each run" I suppose it includes a new python instance or at at least a new start of the python program....in this case it is clearly outside pymodbus/python. If you do not restart python it could be the python garbage collect does not run often enough, I have seen similar problems with python 3.9. Please do not forget you make a new client object for each connection, so pymodbus is "restarted" with each client object creation. |
Try to add "del client" and the end of your loop to force it out. |
so del client is in, but unfortunately it doesn't change anything. The TCP connection is not closed. With TCP, there must be a clean separation on both sides, i.e. my software and the device must terminate the TCP connection cleanly. Otherwise it takes forever for the connection to disconnect. I have tested this with TCP socket, the modbus devices close the connection correctly. |
i have now grouped the ip's with sql join and make a connection for this ip and all modbus adresses. this reduces the problem somewhat. then i have a 60 second break in it, until then all connections are closed. |
Just for info I have tested this specifically on a mac mini with python 3.13. Wireshark shows the FIN packet being sent correctly and netstat shows that the socket is terminated, so pymodbus/asyncio works correctly. |
pymodbus verison is 3.8.6
I go through the database and get the addresses and the ip of the modbus devices and establish the connection. after the wet is saved in the DB, the connection should actually be disconnected. but unfortunately this does not happen.
Too many connections are open after approx. 5 minutes.
x.10 is the server and x.45:502 the modbus devices
Here the Code:
includes:
What am I doing wrong that client.close() does not work?
The text was updated successfully, but these errors were encountered: