Modbus/TCP-Server Timeout

  • Thread starter Steffen Dombrowski
  • Start date
S

Thread Starter

Steffen Dombrowski

My Modbus/TCP-Server can not react to a client shutdown and reboot. My server´s port is still open.
I yet implemented the TCP-Keepalive-option. But for short lasting client shutdown this is not suitable.

I read the Implementation guide for this, but I think it is not sufficient.

Who can make some suggestions to solve this problem ?
 
L

Lynn at Alist

Yes, this is a real problem few beginners foresee. I'll explain for others who haven't got this far yet.

Suppose the MB/TCP client/master is connected to you and all polls have been answered and TCP properly ACK'd. Then either the client crashes or more likely part of the infrastructure drops (routers, satalitte etc). Your server TCP socket could sit passively forever (literally!) waiting for that next request. Even if the recovered client/master comes back in a few seconds or minutes (or hours) and opens a new socket, your server won't know that this is the same "resource" in the client/master's eyes - the TCP source socket number will be different & maybe it's just a 2nd socket.

TCP Keep-alive means your socket will force TCP activity when idle too long - force a new ACK etc. The problem here is that keep-alive often starts in hours, then once it starts it does dozens of retries at exponantially slower times (depends on your stack). So even a keep-alive of say 60 seconds could still require 5 minutes or more to detect socket failure.

Solutions: 1) Having adequate socket resources so that the recoverying client/master can open that 2nd socket while you time-out the 1st!

2) Hack your keep-alive to cause faster failure of sockets. This means reduce the retries used with keep-alive to fewer & faster than normal TCP. I worked with 1 stack that did this - keepalive used just 8 retries and about 30 seconds of time.

3) Create an independent "idle timeout" for your server. Set a default of say 10 minutes (600 seconds), but allow users to disable it or set it to another time. I personally think a 60 second idle timeout is Ok for most Modbus/TCP clients - few OPC or programmer tools WON'T send a poll every second or 2. This time-out just says "if you don't ask me a Modbus poll in N seconds, I'll disconnect you". This is very predictable and FAR EASIER to explain to field techs than TCP keep-alive!

I suggest #1 and #3. If your problem is you don't have a 2nd socket, then you have under-built your product! For an industrial product, you MUST support twice the number of sockets you think the average user will require. A single-socket product is NOT suitable for the market.

Best Regards
- LynnL, www.digi.com
 
Top