[or-cvs] Handle more errnos from accept() without closing the connec...

Nick Mathewson nickm at seul.org
Sun Oct 24 00:55:20 UTC 2004


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv11135/src/or

Modified Files:
	connection.c 
Log Message:
Handle more errnos from accept() without closing the connection.  This may fix a bug that could close OR listeners when (a) TCP connections were hung up before accept() could be called, or (b) during FD exhaustion.

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.266
retrieving revision 1.267
diff -u -d -r1.266 -r1.267
--- connection.c	16 Oct 2004 22:14:51 -0000	1.266
+++ connection.c	24 Oct 2004 00:55:18 -0000	1.267
@@ -385,11 +385,17 @@
 
   news = accept(conn->s,(struct sockaddr *)&remote,&remotelen);
   if (news == -1) { /* accept() error */
-    if(ERRNO_IS_EAGAIN(tor_socket_errno(conn->s))) {
+    int e = tor_socket_errno(conn->s);
+    if (ERRNO_IS_ACCEPT_EAGAIN(e)) {
       return 0; /* he hung up before we could accept(). that's fine. */
+    } else if (ERRNO_IS_ACCEPT_RESOURCE_LIMIT(e)) {
+      log_fn(LOG_WARN,"accept failed: %s. Dropping incomming connection.",
+             tor_socket_strerror(e));
+      return 0;
     }
     /* else there was a real error. */
-    log_fn(LOG_WARN,"accept() failed. Closing listener.");
+    log_fn(LOG_WARN,"accept() failed: %s. Closing listener.", 
+           tor_socket_strerror(e));
     connection_mark_for_close(conn);
     return -1;
   }



More information about the tor-commits mailing list