]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1496832 - Add timeouts to prevent feed daemon from becoming unresponsive
authorDylan William Hardison <dylan@hardison.net>
Tue, 9 Oct 2018 21:01:35 +0000 (17:01 -0400)
committerGitHub <noreply@github.com>
Tue, 9 Oct 2018 21:01:35 +0000 (17:01 -0400)
extensions/PhabBugz/lib/Constants.pm
extensions/PhabBugz/lib/Feed.pm

index 1692f8fb988db394f7b13142dab5a66d7548a4dd..19987de25dab7a74606c58b03b5901fd94b88e8c 100644 (file)
@@ -19,6 +19,7 @@ our @EXPORT = qw(
     PHAB_FEED_POLL_SECONDS
     PHAB_USER_POLL_SECONDS
     PHAB_GROUP_POLL_SECONDS
+    PHAB_TIMEOUT
 );
 
 use constant PHAB_ATTACHMENT_PATTERN => qr/^phabricator-D(\d+)/;
@@ -27,5 +28,6 @@ use constant PHAB_CONTENT_TYPE       => 'text/x-phabricator-request';
 use constant PHAB_FEED_POLL_SECONDS  => $ENV{PHAB_FEED_POLL} // 5;
 use constant PHAB_USER_POLL_SECONDS  => $ENV{PHAB_USER_POLL} // 60;
 use constant PHAB_GROUP_POLL_SECONDS => $ENV{PHAB_GROUP_POLL} // 300;
+use constant PHAB_TIMEOUT            => $ENV{PHAB_TIMEOUT} // 60;
 
 1;
index d8d4d69214f76bd21e6378814801e1888daed5a8..71e6aa827a98035a13dc17287d4022a341b17ecc 100644 (file)
@@ -11,6 +11,7 @@ use 5.10.1;
 
 use IO::Async::Timer::Periodic;
 use IO::Async::Loop;
+use IO::Async::Signal;
 use List::Util qw(first);
 use List::MoreUtils qw(any uniq);
 use Moo;
@@ -47,6 +48,13 @@ my $Invocant = class_type { class => __PACKAGE__ };
 sub start {
     my ($self) = @_;
 
+    my $sig_alarm =  IO::Async::Signal->new(
+        name => 'ALRM',
+        on_receipt => sub {
+            FATAL("Timeout reached");
+            exit;
+        },
+    );
     # Query for new revisions or changes
     my $feed_timer = IO::Async::Timer::Periodic->new(
         first_interval => 0,
@@ -55,13 +63,17 @@ sub start {
         on_tick        => sub {
             try {
                 with_writable_database {
+                    alarm(PHAB_TIMEOUT);
                     $self->feed_query();
                 };
             }
             catch {
                 FATAL($_);
+            }
+            finally {
+                alarm(0);
+                Bugzilla->_cleanup();
             };
-            Bugzilla->_cleanup();
         },
     );
 
@@ -73,13 +85,17 @@ sub start {
         on_tick        => sub {
             try {
                 with_writable_database {
+                    alarm(PHAB_TIMEOUT);
                     $self->user_query();
                 };
             }
             catch {
                 FATAL($_);
+            }
+            finally {
+                alarm(0);
+                Bugzilla->_cleanup();
             };
-            Bugzilla->_cleanup();
         },
     );
 
@@ -91,13 +107,18 @@ sub start {
         on_tick        => sub {
             try {
                 with_writable_database {
+                    alarm(PHAB_TIMEOUT);
                     $self->group_query();
                 };
             }
             catch {
                 FATAL($_);
+            }
+            finally {
+                alarm(0);
+                Bugzilla->_cleanup();
             };
-            Bugzilla->_cleanup();
+
         },
     );
 
@@ -105,6 +126,7 @@ sub start {
     $loop->add($feed_timer);
     $loop->add($user_timer);
     $loop->add($group_timer);
+    $loop->add($sig_alarm);
     $feed_timer->start;
     $user_timer->start;
     $group_timer->start;