INN commit: branches/2.5/lib (Makefile network.c)
INN Commit
rra at isc.org
Sun Jul 17 19:23:27 UTC 2011
Date: Sunday, July 17, 2011 @ 12:23:27
Author: iulius
Revision: 9278
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:
branches/2.5/lib/Makefile
branches/2.5/lib/network.c
-----------+
Makefile | 7 ++++---
network.c | 14 ++++++++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
Modified: Makefile
===================================================================
--- Makefile 2011-07-17 19:21:03 UTC (rev 9277)
+++ Makefile 2011-07-17 19:23:27 UTC (rev 9278)
@@ -217,9 +217,10 @@
../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
../include/config.h ../include/portable/socket.h ../include/config.h \
../include/portable/getaddrinfo.h ../include/portable/getnameinfo.h \
- ../include/portable/wait.h ../include/inn/innconf.h \
- ../include/inn/defines.h ../include/inn/messages.h \
- ../include/inn/network.h ../include/inn/libinn.h
+ ../include/portable/time.h ../include/portable/wait.h \
+ ../include/inn/innconf.h ../include/inn/defines.h \
+ ../include/inn/messages.h ../include/inn/network.h \
+ ../include/inn/libinn.h
newsuser.o: newsuser.c ../include/config.h ../include/inn/defines.h \
../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
../include/config.h ../include/inn/innconf.h ../include/inn/defines.h \
Modified: network.c
===================================================================
--- network.c 2011-07-17 19:21:03 UTC (rev 9277)
+++ network.c 2011-07-17 19:23:27 UTC (rev 9278)
@@ -14,6 +14,7 @@
#include "config.h"
#include "clibrary.h"
#include "portable/socket.h"
+#include "portable/time.h"
#include "portable/wait.h"
#include <errno.h>
#ifdef HAVE_STREAMS_SENDFD
@@ -451,6 +452,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