]> Sergey Matveev's repositories - public-inbox.git/commitdiff
httpd/async: reinstate D::S timer usage for cleanup
authorEric Wong <e@80x24.org>
Sat, 9 Jul 2016 04:51:37 +0000 (04:51 +0000)
committerEric Wong <e@80x24.org>
Sat, 9 Jul 2016 04:52:13 +0000 (04:52 +0000)
EvCleanup::asap events are not guaranteed to run after
Danga::Socket closes sockets at the event loop.  Thus we
must use slower Danga::Socket timers which are guaranteed
to run at the end of the event loop.

lib/PublicInbox/EvCleanup.pm
lib/PublicInbox/HTTPD/Async.pm

index 61837b89d05c4410334810da5cafd2d399dc090a..2b77c617b24f6485c26890b0e6e471209bd26b8b 100644 (file)
@@ -9,6 +9,7 @@ use base qw(Danga::Socket);
 use fields qw(rd);
 my $singleton;
 my $asapq = [ [], undef ];
+my $nextq = [ [], undef ];
 my $laterq = [ [], undef ];
 
 sub once_init () {
@@ -30,6 +31,7 @@ sub _run_all ($) {
 }
 
 sub _run_asap () { _run_all($asapq) }
+sub _run_next () { _run_all($nextq) }
 sub _run_later () { _run_all($laterq) }
 
 # Called by Danga::Socket
@@ -51,6 +53,12 @@ sub asap ($) {
        $asapq->[1] ||= _asap_timer();
 }
 
+sub next_tick ($) {
+       my ($cb) = @_;
+       push @{$nextq->[0]}, $cb;
+       $nextq->[1] ||= Danga::Socket->AddTimer(0, *_run_next);
+}
+
 sub later ($) {
        my ($cb) = @_;
        push @{$laterq->[0]}, $cb;
@@ -59,6 +67,7 @@ sub later ($) {
 
 END {
        _run_asap();
+       _run_next();
        _run_later();
 }
 
index 880cf021cef763a97ea9add08cea295d4c9789fa..68514f5a5a2123b377da389a527280fa19706c25 100644 (file)
@@ -72,7 +72,7 @@ sub close {
        $self->SUPER::close(@_);
 
        # we defer this to the next timer loop since close is deferred
-       PublicInbox::EvCleanup::asap($cleanup) if $cleanup;
+       PublicInbox::EvCleanup::next_tick($cleanup) if $cleanup;
 }
 
 1;