deathwish88 / modbus-tk

Automatically exported from code.google.com/p/modbus-tk
Other
0 stars 0 forks source link

Device re-connection uses a New Socket and Eventually Fails #38

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This is  superb implementation and I have been connecting successfully to an 
RTU using Modbus TCP/IP over Ipsec for several months. 

However the following issue means that the Slave has to be restarted regularly: 

1. The connection is over Ipsec and the other end (Cisco, out of my control) 
renegotiates the connection every 20 mins
2. When the connection is re-established the Master connects with a new Socket
3. This leads to a 'climb' up the sockets and eventually the Slave freezes. 
4. on restart the address is often claimed to be in use

I think there are two issues: 
a) using a new socket each time
b) not releasing the address

I suspect b is the socket library but any help on a) or if it is a bug would be 
great. 

I am using 0.4.2 on Ubuntu 12.04 server, Python 2.7 latest

Original issue reported on code.google.com by nicholas...@gmail.com on 2 Sep 2013 at 9:30

GoogleCodeExporter commented 8 years ago
It seems to be a socket issue. Maybe, there is something wrong in the way we 
use it. Did you try to simulate something similar with just the socket lib?

Original comment by luc.jean@gmail.com on 3 Sep 2013 at 9:17

GoogleCodeExporter commented 8 years ago
Hi - I didn't but I will try

Original comment by nicholas...@gmail.com on 6 Sep 2013 at 6:03

GoogleCodeExporter commented 8 years ago
It seems like the socket library does this anyway - so it is an issue with
the library - I tried setting the socket options to reuse the address but
it doesn't solve this particular problem.

Original comment by nicholas...@gmail.com on 10 Sep 2013 at 4:23

GoogleCodeExporter commented 8 years ago
Hi -

    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

helps with the address in use error that sometimes is thrown up - might
also help with the disconnect issue.

Original comment by nicholas...@gmail.com on 12 Sep 2013 at 7:05

GoogleCodeExporter commented 8 years ago
Hi,

Thanks for feedback. I'll look at it in next version.
Meanwhile, you should be able to force this option on the socket in the 
modbus_tcp.TcpMaster.before_connect hook.

Original comment by luc.jean@gmail.com on 13 Sep 2013 at 8:02

GoogleCodeExporter commented 8 years ago
Fixed on github

Original comment by luc.jean@gmail.com on 29 Apr 2015 at 9:42