LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Solaris / OpenSolaris (https://www.linuxquestions.org/questions/solaris-opensolaris-20/)
-   -   how to handle ECONNABORTED with accept system call? (https://www.linuxquestions.org/questions/solaris-opensolaris-20/how-to-handle-econnaborted-with-accept-system-call-330829/)

murugesan 06-06-2005 07:13 AM

how to handle ECONNABORTED with accept system call?
 
hi all,

i have some code like
Code:

  while(1)
  {
      if(accept()<0)
      {
          if errno==EAGAIN
              continue;
      }
      else
      {
          fork() and handle the new connection.
          exit the child
      }
      continue while in the parent.
  }

In some situation I am receving ECONNABORTED for accept system call.
Now is it advisible to continue the while loop in parent if i recv ECONNABORTED or shall i restart the server instance itself ?


Regards,
Murugesan

technopark02 06-06-2005 05:56 PM

When the client does connect(), it will be queued up at server, waiting to be accept()'ed by the server. But if the client aborts the connection by sending RST (reset) even before server accept()s, then server accept() generates the "connection aborted" (ECONNABORTED) error.

>> Now is it advisible to continue the while loop in parent if i recv ECONNABORTED or shall i restart the server instance itself?

The server should not be vulnerable to errors like these. (How do you like it, if the linuxquestions.org web server restarts itself whenever you changed your mind not to access certain web page, while the server is still processing your request ;)). So, the server should continue listen() as it was listening, and handle the rest of the requests from the listen queue. The code should be changed to:
Code:

      if (accept() < 0) {
          if ((errno == EAGAIN) || (errno == ECONNABORTED) || (.. other errors ..)) {
              perror ("accept(): ");
              continue;
          }
      }

Notes:
1. If you are new to network programming, I would recommend "Beej's Guide to Network Programming" guide. It was mirrored on: http://www-db.stanford.edu/~cho/prog.../network.html.

2. Sometimes it could be a bug too. So, it is always better to post the OS name, version etc., as well, to make it easy for the others to look through the bug/patch reports.

murugesan 06-07-2005 12:45 AM

Thanks for the reply technopark02.

This is what I am using.

/dinesh_p_v/murugesan/c $ uname -a
SunOS sun28 5.8 Generic_117350-12 sun4u sparc SUNW,Ultra-250


> and handle the rest of the requests from the listen queue

Actually my doubt was, will there be any changes to the socket credentials so that the further requests cannot be handled at all and there is a need to restart the server or there is no need to restart the server such that the socket credentials has not been changed after ECONNABORTED error?


Regards,
Murugesan

technopark02 06-07-2005 02:18 PM

>> will there be any changes to the socket credentials so that the further
>> requests cannot be handled at all and there is a need to restart the
>> server or there is no need to restart the server such that the socket
>> credentials has not been changed after ECONNABORTED error?

Depends on various constraints.

1. If the connection hasn't been established yet, i.e., if it is the very first request from the client and if the client closes the connection even before the server got a chance to respond, accept() call at server results in ECONNABORTED. Server should ignore this error and move on with the next request in the queue.

If the client needs to connect to the server again, it has to do another connect().

2. If the connection between client and server is in ESTABLISHED state, and if the client closes the connection abruptly, accept() call at server results in ECONNABORTED. In this scenario, the server must close the connection that is half-open. Otherwise those half-opened sockets may remain in CLOSE_WAIT state, as long as the server process is active. Have a look at this web page: http://technopark02.blogspot.com/200...closewait.html, to know more about CLOSE_WAIT and its impact, in a slightly different scenario.

So, under any circumstances the server need not be restarted if there are some problems at the client end.


All times are GMT -5. The time now is 06:46 PM.