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 b07e184..56d0838 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 5875b73..7192d78 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 $/;
--
unsubscribe: meta+unsubscr...@public-inbox.org
archive: https://public-inbox.org/meta/

Reply via email to