]> git.wh0rd.org Git - tt-rss.git/commitdiff
daemon2: properly abort stuck children
authorAndrew Dolgov <fox@bah.org.ru>
Wed, 25 Aug 2010 14:16:07 +0000 (18:16 +0400)
committerAndrew Dolgov <fox@bah.org.ru>
Wed, 25 Aug 2010 14:16:07 +0000 (18:16 +0400)
functions.php
update_daemon2.php

index 627055f85a9cecaaa26d35099eb61e98518de8c3..7fc5aa7ea41d2fe0b1051e15fbdfb79bdd7a93d3 100644 (file)
 
                        if($debug) _debug("Feed: " . $line["feed_url"] . ", " . $line["last_updated"]);
 
-                       // We setup a alarm to alert if the feed take more than 300s to update.
-                       // => HANG alarm.
-                       if(!$from_http && function_exists('pcntl_alarm')) pcntl_alarm(300);
-                       update_rss_feed($link, $line["id"], true);
-                       // Cancel the alarm (the update went well)
-                       if(!$from_http && function_exists('pcntl_alarm')) pcntl_alarm(0);
-
                        sleep(1); // prevent flood (FIXME make this an option?)
                }
 
index 431f0b6a11d62dc8a40f89ec42ac142928be060b..9747d523354e95ee7c6ecde839051d8550090627 100755 (executable)
        }
 
        define('PURGE_INTERVAL', 3600); // seconds
+       define('MAX_CHILD_RUNTIME', 600); // seconds
 
        require_once "sanity_check.php";
        require_once "config.php";
 
        define('MAX_JOBS', 2);
+       define('SPAWN_INTERVAL', 1);
 
        define('SPAWN_INTERVAL', DAEMON_SLEEP_INTERVAL);
 
@@ -41,6 +43,7 @@
        error_reporting(DEFAULT_ERROR_LEVEL);
 
        $children = array();
+       $ctimes = array();
 
        $last_checkpoint = -1;
 
@@ -54,6 +57,7 @@
                                array_push($tmp, $pid);
                        } else {
                                _debug("[SIGCHLD] child $pid reaped.");
+                               unset($ctimes[$pid]);
                        }
                }
 
                return count($tmp);
        }
 
-       function sigalrm_handler() {
-               die("[SIGALRM] hang in feed update?\n");
+       function check_ctimes() {
+               global $ctimes;
+               
+               foreach (array_keys($ctimes) as $pid) {
+                       $started = $ctimes[$pid];
+
+                       if (time() - $started > MAX_CHILD_RUNTIME) {
+                               _debug("[MASTER] child process $pid seems to be stuck, aborting...");
+                               posix_kill($pid, SIGINT);
+                       }
+               }
        }
 
        function sigchld_handler($signal) {
@@ -79,7 +92,6 @@
                die("[SIGINT] removing lockfile and exiting.\n");
        }
 
-       pcntl_signal(SIGALRM, 'sigalrm_handler');
        pcntl_signal(SIGCHLD, 'sigchld_handler');
 
        if (file_is_locked("update_daemon.lock")) {
 
                if ($last_checkpoint + SPAWN_INTERVAL < time()) {
 
+                       check_ctimes();
                        reap_children();
 
                        for ($j = count($children); $j < MAX_JOBS; $j++) {
                                } else if ($pid) {
                                        _debug("[MASTER] spawned client $j [PID:$pid]...");
                                        array_push($children, $pid);
+                                       $ctimes[$pid] = time();
                                } else {
                                        pcntl_signal(SIGCHLD, SIG_IGN);
                                        pcntl_signal(SIGINT, SIG_DFL);