Solved

TCP connections not failing

Posted on 1998-12-15
5
322 Views
Last Modified: 2013-12-06
I have a TCP server process running on a HP-UX box accepting connection from a quenix client. Sometimes when the quenix box goes down, the server waiting on a connected blocked 'recv' socket, does not come out, meanwhile client gets re-started and gets re-connected to the server [ Server has backlog of upto 5 ]. Is there a setting or parameter which could fix this problem? Also, the connection between the two is thru a T1 line [If that makes any difference at all ]
0
Comment
Question by:mmanju
  • 2
  • 2
5 Comments
 

Author Comment

by:mmanju
ID: 2008429
Edited text of question
0
 
LVL 2

Accepted Solution

by:
rdelfino earned 100 total points
ID: 2008430

You have got to set the SO_KEEPALIVE option on the  socket
right after you accept() the connection. Doing so, the OS will
probe if the client is still alive and the blocked recv() will return
with an error.  

The problem is that the kernel waits from 30 seconds up to 12 hours for response on the socket. So, if the client is restarted in
a smaller time than the time the kernel finds out the socket is
no longer alive, you may have another pending connection from the client that restarted while you are blocked on recv().

It is possible to config the waiting time in a config file that is read at boot time (Sorry, but I don't know which file is this in HP-UX).

Also, try spanning a thread/process to treat new connections.
This way you can accept() new connections while the child
processes/threads are blocked on recv().

The piece of code below show setting the SO_KEEPALIVE
option and spanning a new proccess to treat the new
connection.

/* . . . . . .  */

int aux;
int s;
int listenSocket;
char buff[BUFFSIZE];

/* . . . . */

for(;;)
{
  s = accept(listenSocket, NULL, NULL);

  if (s < 0)
  {
    continue;
  }
  aux = 1;
  setsockopt(s, SOL_SOCKET,  SO_KEEPALIVE, &aux, \
  sizeof(int));
 

  if (!fork())
  {
    /* child proccess */
    close(listenSocket);
    /* . . . . */  

    recv(s, buff, BUFFSIZE);
   
    /* . . . */
  }
  close(s);
}

I hope it helps

Reginaldo

0
 

Author Comment

by:mmanju
ID: 2008431
Would it be possible to tell me the name of the file on an AIX box or any UNIX box for that matter, which can give me a hint for looking into HP-UX files?
0
 

Expert Comment

by:rajeevm
ID: 2008432
Hello
CAN YOU PLEASE TRY CHANGING THE TCP KEEP ALIVE INTERVAL BY USING
NO COMMAND .
REGARDS,
Rajeev Mishra
0
 

Expert Comment

by:rajeevm
ID: 2008433
while adding the previous comment the link went down so i was not knowing what got added , the above suggestion is for AIX box
only ,i am not familiar with HP
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question