LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 08-29-2005, 06:43 AM   #1
gecoool
Member
 
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-29-2005, 11:18 PM   #2
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 51
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
(like)
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
close(connection);
exit(0);
and
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-29-2005, 11:38 PM   #3
paulsm4
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:

http://www.linuxquestions.org/questi...ight=time_wait

PS:
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, 01:02 AM   #4
gecoool
Member
 
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.
 
  


Reply


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


All times are GMT -5. The time now is 12:44 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration