LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   TCP keep alive and socket termination (https://www.linuxquestions.org/questions/programming-9/tcp-keep-alive-and-socket-termination-769600/)

gdkool 11-17-2009 01:16 AM

TCP keep alive and socket termination
 
Hi,

If there is an ESTABLISHED TCP socket over any interface, and the underlying interface is brought down (ifconfig <ifname> down), then the TCP keep-alive mechanism comes to rescue (this however requires turning on the SO_KEEPALIVE socket option). The keep-alive mechanism will probe whether the connection is alive or not after keepalive intervals. (configurable through /proc/sys/net/ipv4/tcp_keepalive_*). I have set the probes to 16 and interval as 1.

But if some data is pumped over this socket after bringing the interface down and when the probing mechanism is in progress, then it gets buffered in the TCP send queue and stays there till the connection breaks. My problem is that, in such scenario, the keep alive mechanism takes too long (say 15-20 mins with this configuration) to terminate the connection which would otherwise take a few seconds.

So, can anyone please let me know on how to get rid off the buffered bytes in the send queue and terminate the connection as per the configuration (keep alive probes and timeout interval).

Regards,
gdkool

kbp 11-19-2009 04:59 PM

Can you tell us what setting you used for tcp_keepalive_time ? .. this configures how many seconds to wait after the last data packet before sending any probes

cheers

gdkool 11-20-2009 02:49 AM

Quote:

Originally Posted by kbp (Post 3763214)
Can you tell us what setting you used for tcp_keepalive_time ? .. this configures how many seconds to wait after the last data packet before sending any probes

cheers

The interval has been kept as 1 sec and number of probes as 16. These settings works fine if there is no data sent over the socket when the keep-alive mechanism is in progress. But as I have stated in my last post, as soon as the interface is brought down, some data is immediately sent over it which causes the problem. Hope I've made my point clear.

Regards
gdkool

kbp 11-20-2009 06:48 AM

I wasn't talking about tcp_keepalive_intvl, as per my previous post - have you set tcp_keepalive_time ? ... please see this link:

http://tldp.org/HOWTO/TCP-Keepalive-...keepalive.html

cheers

gdkool 11-21-2009 12:47 AM

That too was set to 1 sec.

Quote:

Originally Posted by kbp (Post 3763786)
I wasn't talking about tcp_keepalive_intvl, as per my previous post - have you set tcp_keepalive_time ? ... please see this link:

http://tldp.org/HOWTO/TCP-Keepalive-...keepalive.html

cheers


kbp 11-21-2009 05:32 AM

You may need to run a sniffer to see what's happening, do you have tcpdump or ethereal/wireshark installed ?

gdkool 11-22-2009 03:20 AM

Thanks for your update... I will check it out and then update..

Quote:

Originally Posted by kbp (Post 3764802)
You may need to run a sniffer to see what's happening, do you have tcpdump or ethereal/wireshark installed ?



All times are GMT -5. The time now is 02:00 AM.