Solved

TCP connections not failing

Posted on 1998-12-15
5
311 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now