From 6e238ee3396719e578d6a90e177a71ce9f8c1ca0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 2 Jul 2016 21:50:30 +0000 Subject: [PATCH] nntp: respect 3 minute idle time for shutdown This avoids breaking clients on graceful shutdown since NNTP responses should usually be quick. --- lib/PublicInbox/NNTP.pm | 15 ++++++++++++--- t/nntpd.t | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index b07e1845..56d08385 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -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; diff --git a/t/nntpd.t b/t/nntpd.t index 5875b737..7192d781 100644 --- 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 $/; -- 2.44.0