From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 69FF22070F for ; Sat, 9 Jul 2016 04:51:40 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/2] httpd/async: reinstate D::S timer usage for cleanup Date: Sat, 9 Jul 2016 04:51:37 +0000 Message-Id: <20160709045137.7314-3-e@80x24.org> In-Reply-To: <20160709045137.7314-1-e@80x24.org> References: <20160709045137.7314-1-e@80x24.org> List-Id: 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 | 9 +++++++++ lib/PublicInbox/HTTPD/Async.pm | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/EvCleanup.pm b/lib/PublicInbox/EvCleanup.pm index 61837b8..2b77c61 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 880cf02..68514f5 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; -- EW