diff options
author | Eric Wong <e@80x24.org> | 2016-07-09 04:51:37 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-07-09 04:52:13 +0000 |
commit | 63d2e98ce28ddfefeac8bfdac409eae5efc03a9f (patch) | |
tree | 4dec15e825511818f21262f3174f0fcb6b0cae55 | |
parent | acd3a41f52167b8e41cf34ab8164a9dfb5ef9c5c (diff) | |
download | public-inbox-63d2e98ce28ddfefeac8bfdac409eae5efc03a9f.tar.gz |
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.
-rw-r--r-- | lib/PublicInbox/EvCleanup.pm | 9 | ||||
-rw-r--r-- | lib/PublicInbox/HTTPD/Async.pm | 2 |
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/PublicInbox/EvCleanup.pm b/lib/PublicInbox/EvCleanup.pm index 61837b89..2b77c617 100644 --- a/lib/PublicInbox/EvCleanup.pm +++ b/lib/PublicInbox/EvCleanup.pm @@ -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(); } diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm index 880cf021..68514f5a 100644 --- a/lib/PublicInbox/HTTPD/Async.pm +++ b/lib/PublicInbox/HTTPD/Async.pm @@ -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; |