Skip Menu |

This queue is for tickets about the Device-Modbus-TCP CPAN distribution.

Report information
The Basics
Id: 121793
Status: patched
Priority: 0/
Queue: Device-Modbus-TCP

People
Owner: JFRAIRE [...] cpan.org
Requestors: oliviercommelarbre [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: server not closing client connections
Date: Sat, 20 May 2017 01:06:10 +0200
To: bug-Device-Modbus-TCP [...] rt.cpan.org
From: Olivier Colin <oliviercommelarbre [...] gmail.com>
Dear JFRAIRE, I've started using both the Modbus TCP client and server modules and they work great sofar for my application, thank you!! I found just this little annoying bug which i could correct easily with a one line patch in Device/Modbus/TCP/Server.pm. the problem is on the server side (Device::Modbus::TCP::Server). when the client disconnects, or when the 5s timeout expires on reading a modbus request on the server side, the event is well cought in the code (in the catch block in Device/Modbus/TCP/Server.pm line#63), however the socket does not get actually closed (even though it is inoperative or timed out), so the code never leaves the while loop that keeps trying to read incoming requests. The problem is that the condition for staying in the loop ($self->socket->connected) will never return false even though the client has left the connection. In fact, the IO::Socket->connected method returns false only when the socket has been locally closed. I found the explanation here: http://www.perlmonks.org/?node_id=300813. Hence to solve the problem, it is just needed to locally close the socket in the catch block in question with: $self->socket->close; I've tested and it works now like a dream, lost client connections cr idle ones (for more than 5secs) are cleanly closed and released by the server. I hope you can integrate in your next release on cpan, please do not hesitate to ask more details if you need. wishing you a good continuation and thank you again! Olivier
Hello Olivier, First of all, thank you for taking the time for investigating and finding the solution for this problem. I have just modified the code following your instructions and Device::Modbus::TCP is just now hitting CPAN with revision 0.025. The fix you suggested as well as another fix in line 33 of Device::Modbus::TCP are geared towards unexpected client disconnection. I think you both hit the same bug and fixed it in different ways. Both are included in this revision. I hope this revision will succeed in getting rid of this problem. Thank you again and best regards, Julio