From: Eric Wong <e@80x24.org>
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 [thread overview]
Message-ID: <20160709045137.7314-3-e@80x24.org> (raw)
In-Reply-To: <20160709045137.7314-1-e@80x24.org>
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
prev parent reply other threads:[~2016-07-09 4:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-09 4:51 [PATCH 0/2] httpd/async race fixes Eric Wong
2016-07-09 4:51 ` [PATCH 1/2] httpd/async: do not attempt future writes on closed sockets Eric Wong
2016-07-09 4:51 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160709045137.7314-3-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).