Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCP Connect error 115 Operation in Progress What is the Cause?

My application creats a TCP connection, This is working normaly. But in one network server has many IP say

  • 174.X.X.X
  • 54.x.x.x like this

When calling TCP connect (Non blocking with timeout of 60 seconds) to IP 174.X.X.X is always success . But TCP connect to same server with ip 54.x.x.x is failing (most of the times) with errno 115 measn operation in progress.

Can you please explain me what are the possible reason for errno 115

OS : Linux

My TCP conenct code is as below

tcp_connect(......)
{

  int iValOpt = 0;  
  int iLength= 0;

  fcnt((int)(long)SockID,F_SETFL_O_NONBLOCK);

  ret = connect (sockID,(struct sockaddr*)pstSockAdr,uiSockLen);

  if (ret < 0)
  {

        if (errno == EINPROGRESS)
        {
                stTv.tv_sec = 60;
                stTv.tv_usec = 0;
                FD_ZERO(&write_fd);
                FD_SET(sockID,&write_fd);

                iLength = sizeof(int);

                if (0 < select (sockID+1) , NULL,&write_fd,NULL,&stTv);

                {
                        if(0 > getsockopt(sockID,SOL_SOCKET,SO_ERROR,(void*)(&iValOpt),&iLength))
                        {
                                return -1
                        }

                        if (0 != iValOpt)
                        {
                                return -1;
                        }


                        return success;
                }

                else
                {
                        return -1;
                }   

        }
        else
        {
                return -1;
        }
    }

   return success;

}
like image 431
Syed Shamsheer Avatar asked Apr 18 '12 06:04

Syed Shamsheer


People also ask

Why does TCP connection fail?

The main causes for failed connection requests at a Distributed Relational Database Architecture™ (DRDA) server configured for TCP/IP use is that the DDM TCP/IP server is not started, an authorization error occurred, or the machine is not running.

What is a TCP error?

A service error, such as where the service that should be listening on a port has crashed or is otherwise unavailable.

What does mount error 115 mean?

Mount error(115): Operation now in progress Cause A network name resolution failing on the smb client in LEM. Resolution Check ICMP connectivity (ping) between the hosts. Attempt to mount a share on the same subnet as

Why do I get einprogress error when connecting to a socket?

Since the connect () operation is already in progress, any subsequent operation on the socket is resulting into EINPROGRESS error code. As suggested in the man page, try to use select () or poll () to check if your socket is ready to use (to perform read () or write () calls).

What happens if the socket connection request fails?

If the connection cannot be established immediately and O_NONBLOCK is set for the file descriptor for the socket, connect () shall fail and set errno to [EINPROGRESS], but the connection request shall not be aborted, and the connection shall be established asynchronously.


1 Answers

Based on your information:

  • You are trying to do a connect() to 54.x.x.x
  • The socket is non-blocking
  • Connection timeout is 60 sec

First, if you look into your /usr/include/asm-generic/errno.h you'll see the following:

#define EINPROGRESS     115     /* Operation now in progress */

It means an existing operation on the socket is in progress. Since, you said you are doing a connect() call, lets do a man connect:

EINPROGRESS

The socket is nonblocking and the connection cannot be completed 
immediately. It is possible to select(2) or poll(2) for completion by
selecting the socket for writing. After select(2) indicates
writability, use getsockopt(2) to read the SO_ERROR option at level
SOL_SOCKET to determine whether connect() completed successfully
(SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual
error codes listed here, explaining the reason for the failure).

So, the best guess would be that the TCP 3-way handshake (your connect() call to 54.x.x.x IP address) is taking longer than expected to complete. Since the connect() operation is already in progress, any subsequent operation on the socket is resulting into EINPROGRESS error code. As suggested in the man page, try to use select() or poll() to check if your socket is ready to use (to perform read() or write() calls).

You can pin-point what is preventing your TCP handshake to complete by capturing and analyzing the traffic to/from your own machine and 54.x.x.x. The best tool to help you with this is called WireShark. Good luck.

TCP 3 way handshake

like image 140
gsbabil Avatar answered Sep 18 '22 00:09

gsbabil