Strange Connection refused error. Maybe kernel guru required?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.