INN commit: trunk/lib (network.c)

INN Commit rra at isc.org
Mon Jul 11 09:39:33 UTC 2011


    Date: Monday, July 11, 2011 @ 02:39:33
  Author: iulius
Revision: 9237

add a default timeout on outgoing sockets (NNTPconnect)

For a long time, there have been occasional problems with actsync
syncing from certain servers:  instead of erroring out and exiting (with
"cannot connect to server: Connection timed out" or alternatively
"cannot connect to server: Success"), actsync would hang until manually
killed, sometimes for days.

gdb shows actsync is hanging in a call to fgets in NNTPconnect() (from
actsync.c:get_active()).
innxmit and innxbatch can use alarm() to set a timeout but other users of
NNTPconnect, such as nntpget, rnews, clientlib.c and nnrpd/post.c
apparently don't.

Implement SO_RCVTIMEO with the default timeout of 300 seconds (set in
include/inn/options.h).

The raised error will be:
"actsync: cannot connect to server: Resource temporarily unavailable"

Thanks to Florian Schlichting for the patch.

Modified:
  trunk/lib/network.c

-----------+
 network.c |   13 +++++++++++++
 1 file changed, 13 insertions(+)

Modified: network.c
===================================================================
--- network.c	2011-07-11 09:11:20 UTC (rev 9236)
+++ network.c	2011-07-11 09:39:33 UTC (rev 9237)
@@ -451,6 +451,19 @@
             break;
         }
     }
+
+#ifdef SO_RCVTIMEO
+    struct timeval connect_timeout;
+    connect_timeout.tv_sec = DEFAULT_TIMEOUT;
+    connect_timeout.tv_usec = 0;
+
+    if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &connect_timeout, sizeof(connect_timeout)) < 0) {
+        syswarn("setsockopt SO_RCVTIMEO %d failed", DEFAULT_TIMEOUT);
+        /* No need to return an error, as failure would just be like before
+         * (no timeout on socket).  Better create the socket anyway! */
+    }
+#endif
+
     if (success)
         return fd;
     else {




More information about the inn-committers mailing list