LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-17-2009, 01:16 AM   #1
gdkool
LQ Newbie
 
Registered: Nov 2007
Posts: 19

Rep: Reputation: 0
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
 
Old 11-19-2009, 04:59 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
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
 
Old 11-20-2009, 02:49 AM   #3
gdkool
LQ Newbie
 
Registered: Nov 2007
Posts: 19

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by kbp View Post
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
 
Old 11-20-2009, 06:48 AM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
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
 
Old 11-21-2009, 12:47 AM   #5
gdkool
LQ Newbie
 
Registered: Nov 2007
Posts: 19

Original Poster
Rep: Reputation: 0
That too was set to 1 sec.

Quote:
Originally Posted by kbp View Post
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
 
Old 11-21-2009, 05:32 AM   #6
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
You may need to run a sniffer to see what's happening, do you have tcpdump or ethereal/wireshark installed ?
 
Old 11-22-2009, 03:20 AM   #7
gdkool
LQ Newbie
 
Registered: Nov 2007
Posts: 19

Original Poster
Rep: Reputation: 0
Thanks for your update... I will check it out and then update..

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tcp connection is alive or not krishna123 Programming 5 11-06-2009 04:17 AM
Connection Failed due to: TCP/IP ports not alive !!! penguinux Linux - Newbie 1 11-21-2008 09:23 AM
HTTP Keep-Alive socket problem imdupeng Programming 1 03-29-2008 11:17 AM
PHP - Check if Socket is alive baddah Programming 6 12-11-2007 08:50 AM
TCP Keep alive Option Performance impact ndwivedi Linux - Software 0 06-24-2004 01:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration