timeout switch for actsync
Florian Schlichting
fschlich at CIS.FU-Berlin.DE
Tue Jun 28 11:01:49 UTC 2011
Hi Julien,
> >gdb shows actsync is hanging in a call to fgets in NNTPconnect() (from
> >actsync.c:get_active()). While I don't understand why fgets doesn't
> >return when the TCP connection times out, looking around I found that
> >innxmit and innxbatch can use alarm() to set a timeout (other users of
> >NNTPconnect, such as nntpget, rnews, clientlib.c and nnrpd/post.c
> >apparently don't).
>
> I think the best solution would be to implement the timeout directly
> in NNTPconnect, around the call to fgets().
>
> An interesting thread to read here, in case it could interest you:
> http://stackoverflow.com/questions/1715413/longjmp-from-signal-handler
that's an interesting discussion indeed. I think the sigaction() version
is a lot nicer than using longjmp / siglongjmp. Reading around a little,
I found yet another approach to my problem: Why don't we set a timeout
on the network socket when we create it? connect() seems to make use of
a timeout, but after that, other reads/writes block indefinitely by
default.
Something like this:
"actsync: cannot connect to server: Resource temporarily unavailable"
doesn't sound too misleading?
---
lib/network.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/lib/network.c b/lib/network.c
index 0c09502..c415baa 100644
--- a/lib/network.c
+++ b/lib/network.c
@@ -435,6 +435,9 @@ network_connect(struct addrinfo *ai, const char *source)
int fd = -1;
int oerrno;
bool success;
+ struct timeval connect_timeout;
+ connect_timeout.tv_sec = 300;
+ connect_timeout.tv_usec = 0;
for (success = false; ai != NULL; ai = ai->ai_next) {
if (fd >= 0)
@@ -449,6 +452,10 @@ network_connect(struct addrinfo *ai, const char *source)
break;
}
}
+ if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &connect_timeout, sizeof(connect_timeout)) != 0) {
+ syswarn("setsockopt SO_RCVTIMEO 300 failed");
+ /*return false; <- not needed, as failure would just be like before? */
+ }
if (success)
return fd;
else {
And what should such a compulsory timeout be, 300s like TCP or
rather something shorter like 30s?
And how about SO_SNDTIMEO?
I feel a little bit uneasy hacking on these librarys as I don't really
know in which places the code might get used...
Florian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5557 bytes
Desc: not available
URL: <https://lists.isc.org/pipermail/inn-workers/attachments/20110628/0d08559b/attachment.bin>
More information about the inn-workers
mailing list