]> Sergey Matveev's repositories - public-inbox.git/commitdiff
nntp: respect 3 minute idle time for shutdown
authorEric Wong <e@80x24.org>
Sat, 2 Jul 2016 21:50:30 +0000 (21:50 +0000)
committerEric Wong <e@80x24.org>
Sat, 2 Jul 2016 21:52:30 +0000 (21:52 +0000)
This avoids breaking clients on graceful shutdown since
NNTP responses should usually be quick.

lib/PublicInbox/NNTP.pm
t/nntpd.t

index b07e1845c2321962bb7962a926cc04032ce10aff..56d08385da0f6a4b924e07ffb01662ad288f0715 100644 (file)
@@ -998,10 +998,19 @@ sub watch_read {
        $rv;
 }
 
+sub not_idle_long ($$) {
+       my ($self, $now) = @_;
+       defined(my $fd = $self->{fd}) or return;
+       my $ary = $EXPMAP->{$fd} or return;
+       my $exp_at = $ary->[0] + $EXPTIME;
+       $exp_at > $now;
+}
+
 # for graceful shutdown in PublicInbox::Daemon:
-sub busy () {
-       my ($self) = @_;
-       ($self->{rbuf} ne '' || $self->{long_res} || $self->{write_buf_size});
+sub busy {
+       my ($self, $now) = @_;
+       ($self->{rbuf} ne '' || $self->{long_res} || $self->{write_buf_size} ||
+        not_idle_long($self, $now));
 }
 
 1;
index 5875b737360b35a41803f1327339e6fe8e4f2e0d..7192d7819dd6d12e9a758581da373042cc39091b 100644 (file)
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -219,6 +219,7 @@ EOF
                is(scalar @r, 1, 'only one response line');
        }
 
+       $n = $s = undef;
        is($pid, waitpid($pid, 0), 'nntpd exited successfully');
        my $eout = eval {
                local $/;