LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-25-2004, 05:46 AM   #1
shy
Member
 
Registered: Dec 2002
Location: Russia
Distribution: ASP linux
Posts: 94

Rep: Reputation: 15
Strange Connection refused error. Maybe kernel guru required?


Hi.
I'm making a test application for measuring the speed of TCP connection in the following way:

I have 2 linux boxes (Server and Client), connected via ethernet cable (both cards are 100mb). Server application binds a listening socket, and waits incoming connections in accept() call N times (N is a command line parameter). Each time it accepts a connection, it pthread_creates a thread, which reads a stream from socket and saves it into a separate file. Size of stream is passed in first 4 bytes of it. When saving is finished, thread closes file, writes 1 byte to socket, and closes socket.

Client application pthread_creates N threads (where N is the same as for the server), each of which initiates connection to server, opens a separate file, writes its size and contents into socket, and reads one byte as a sign of finish on the server side. After that it closes the connection.

I run client and server applications from bash-scripts which constantly increase the parameter N and measure the speed of file transfers. The problem is that on some step (usually when N is somewhere between 30 and 50) one (and only one) of client threads receives a connection refused error from connect() call. But tcpdump shows that there are no SYN segments from client side without SYN-ACK replies from the server (and RST is also not sent by the server). The time spent in connect() call is something about 0.1 sec, so I think that the client's kernel decides to return a ECONNREFUSED not actually performing a three-way handshake.

Could anyone please tell me where in kernel the problem may be (and can it be really in kernel)? Client's kernel is 2.4.20 and server's is 2.6.8.1 if it can help.

Last edited by shy; 10-26-2004 at 04:48 AM.
 
Old 10-25-2004, 10:09 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
What size queue are you using for listen()?
 
Old 10-25-2004, 11:04 AM   #3
shy
Member
 
Registered: Dec 2002
Location: Russia
Distribution: ASP linux
Posts: 94

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by itsme86
What size queue are you using for listen()?
I used 10, 100 and 1024 (which was the default maximum in /proc/sys/net/ipv4/tcp_max_syn_backlog). And the failures begin to appear at 30-40 simultaneous connects. I think, backlog=100 should be quite enough to handle this.

But, as I have already mentioned, there were no SYNs from client without SYN-ACKs from server, and no RSTs from server to client.
As far as I know, exceeding backlog parameter results in RST. Correct me if I'm wrong.

Last edited by shy; 10-25-2004 at 01:24 PM.
 
Old 10-27-2004, 11:35 AM   #4
shy
Member
 
Registered: Dec 2002
Location: Russia
Distribution: ASP linux
Posts: 94

Original Poster
Rep: Reputation: 15
Well, strace helped.

Time to time gethostbyname() returned "127.0.0.1" instead of "10.0.0.1" for the server address.

My distro's manpage for this function didn't contain any multithread info, but google told me:

Quote:
From Solaris manpage
The functions gethostbyname(), gethostbyaddr(), and gethostent() use static storage that is re-used in each call, making these functions unsafe for use in multithreaded applications.

The functions gethostbyname_r(), gethostbyaddr_r(), and gethostent_r() provide reentrant interfaces for these operations.
 
  


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
Connection refused error for port 25 jgnasser Linux - Networking 3 08-25-2004 07:09 AM
Connection refused error sweetyedwin Linux - Networking 1 07-15-2004 03:11 AM
Guru advise required LuggerHouse Linux - Networking 0 05-12-2004 02:24 PM
Strange "Connection Refused" Error..... tictocdoc Linux - Networking 4 03-29-2004 04:16 PM
Connection refused error robs4linux Linux - Networking 2 03-19-2002 02:09 PM

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

All times are GMT -5. The time now is 05:33 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration