Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 08-29-2005, 07:43 AM   #1
Registered: Feb 2005
Location: Romania
Distribution: Fedora 2
Posts: 38

Rep: Reputation: 15
time_wait problem

Hello everyone. My problem: i have a small app written in c++(linux: fedora core 1), which is listening on a given port, receives a query word, then it searches a database, for it and it returns to the client an answer(array of strings), and then it closes the conection (small daemon, multithreaded). Even if i close the conection on the client side too, after I successfully received the answer, the connection however remains in TIME_WAIT for a very long time, causing the server to reach max connections, and stop responding. What i am seeking help for is: how to reduce time_wait ?

Please Help ! THX.
Old 08-30-2005, 12:18 AM   #2
Senior Member
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 52
i too have had troubles with long glibc socket time out.
it seems to have to do with getpeername or getadressbyname or getsockname or something similar
so possibly some problem with lookup going on ?
all i know to say without seeing code is
loop with accept()
accept blocks untill a connection comes in
create a new socket
int connection;
connection = accept()
then fork
once you fork to handle the connection
close the server socket within the child so the child doesn't interfear with that
then pass the new handeling socket to a method or however you handle
and when that returns
write a handler for SIGCHILD to clean up child processes

can't see how that can hang on you unless like i said it gets stuck looking something up
Old 08-30-2005, 12:38 AM   #3
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Please consider increasing the #/ephemeral ports before you go decreasing time wait. Details on both can be found in this thread:

In your case, there doesn't seem to be any danger of "duplicate port numbers", so decreasing time_wait isn't as risky as it might be in, say, a high-end stock trading application.

You might also wish to consider trying UDP instead of TCP: less overhead, better response ... and no such thing as "time wait" to worry about.

Just a thought .. PSM
Old 08-31-2005, 02:02 AM   #4
Registered: Feb 2005
Location: Romania
Distribution: Fedora 2
Posts: 38

Original Poster
Rep: Reputation: 15
THX U all for your time ;-), first

for foo_bar_foo: I used ONLY IP's (not friendly host name). However inspecting connection status with netstat -tn revealed connections in time_wait state, which, according to my knowledge occurs only after both ends have closed the connection.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
too many "TIME_WAIT" on apache2 jiawj Linux - Software 0 06-14-2005 10:19 AM
MSL and TCP time_wait 98steve600 Linux - General 1 03-28-2005 04:45 AM
How do I close TIME_WAIT connections? linuxboy69 Linux - Software 2 09-01-2004 05:13 PM
TIME_WAIT and too many sockets in that state dkumar10 Linux - Networking 1 07-16-2004 07:59 AM
perl problem? apache problem? cgi problem? WorldBuilder Linux - Software 1 09-17-2003 08:45 PM > Forums > Linux Forums > Linux - Software

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

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