[PATCH] fixes for throttling mode of snget

[email protected]
Newsgroups gmane.network.sn
Organization none
Message-ID <[email protected]>
Here is a patch for sn-0.3.6 that fixes two problems with the
throttling implementation in snget (-h option). I was occasionally
experiencing hanging snget processes, caused by failed connections to
the upstream NNTP server.

The first problem is that the writing side of the pipe is not closed
in the child process for HELLO/snfetch. As a result, /usr/sbin/HELLO
will hang when the upstream NNTP server is unreachable. This problem
is fixed by adding a close(p[1]) in the child process.

The second problem is that the throttling code of snget ignores read
errors, for instance when the upstream server is not reachable, or
when the connection breaks. Because the read error is ignored, snget
will keep calling select() and read(), using 100% CPU. The read error
is now propagated by closing the write side of the pipe.

--- orig/sn-0.3.6/get.c	2002-11-12 21:00:28.000000000 +0100
+++ sn-0.3.6/get.c	2003-07-26 17:06:55.000000000 +0200
@@ -416,7 +416,7 @@
    bytes = 0;
    for (i = 0; i < toff; i++)
       if (queue[i]->infd > -1 && FD_ISSET(queue[i]->sd, rs))
-         /* ignore socket read errors */
+      {
          if ((c = read(queue[i]->sd, buf, sizeof (buf))) > 0)
          {
             if (-1 == write(queue[i]->infd, buf, c))
@@ -428,6 +428,13 @@
             else
                bytes += c;
          }
+         else if (c < 0)
+         {  /* close pipe on socket error */
+            log("throttle:read: %m", c);
+            close(queue[i]->infd);
+            queue[i]->infd = -1;
+         }
+      }
 
    gettimeofday(&last, 0);
 }
@@ -594,7 +601,10 @@
                if ((jp->pid = fork()) > -1)
                {
                   if (0 == jp->pid)
+                  {
+                     close(p[1]);
                      break;
+                  }
                   if (throttlerate)
                   {
                      close(p[0]);

-- 
Dick Streefland                    ////               De Bilt
[email protected]         (@ @)       The Netherlands
------------------------------oOO--(_)--OOo------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.