From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id D3B241F466; Thu, 26 Dec 2019 07:53:07 +0000 (UTC) Date: Thu, 26 Dec 2019 07:53:07 +0000 From: Eric Wong To: meta@public-inbox.org Subject: Re: [PATCH 02/30] httpd/async: support passing arg to callbacks Message-ID: <20191226075307.GA4890@dcvr> References: <20191225075104.22184-1-e@80x24.org> <20191225075104.22184-3-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20191225075104.22184-3-e@80x24.org> List-Id: Eric Wong wrote: > index eea59b6d..d59320bc 100644 > --- a/lib/PublicInbox/SolverGit.pm > +++ b/lib/PublicInbox/SolverGit.pm > @@ -363,18 +363,13 @@ sub do_step ($) { > } > } > > -sub step_cb ($) { > - my ($self) = @_; > - sub { do_step($self) }; > -} > - > sub next_step ($) { > my ($self) = @_; > # if outside of public-inbox-httpd, caller is expected to be > - # looping step_cb, anyways > + # looping do_step, anyways > my $async = $self->{psgi_env}->{'pi-httpd.async'} or return; > # PublicInbox::HTTPD::Async->new > - $async->(undef, step_cb($self)); > + $async->(undef, \&do_step, $self); > } > > sub mark_found ($$$) { > @@ -598,12 +593,11 @@ sub solve ($$$$$) { > $self->{tmp} = File::Temp->newdir("solver.$oid_want-XXXXXXXX", TMPDIR => 1); > > dbg($self, "solving $oid_want ..."); > - my $step_cb = step_cb($self); > if (my $async = $env->{'pi-httpd.async'}) { > # PublicInbox::HTTPD::Async->new > - $async->(undef, $step_cb); > + $async->(undef, \&do_step, $self); > } else { > - $step_cb->() while $self->{user_cb}; > + do_step($self) while $self->{user_cb}; > } > } > Those calls to $async->(...) were wrong, given how HTTPD::Async->new works in the '!defined($io)' path. Failures were exposed using the async API: https://public-inbox.org/meta/20191226064804.23024-4-e@80x24.org/ So we'll rename do_step to event_step and rely on DS::requeue to call it, instead: diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm index 70769bba..d182c118 100644 --- a/lib/PublicInbox/HTTPD/Async.pm +++ b/lib/PublicInbox/HTTPD/Async.pm @@ -23,7 +23,7 @@ sub new { # no $io? call $cb at the top of the next event loop to # avoid recursion: unless (defined($io)) { - PublicInbox::DS::requeue($cb); + PublicInbox::DS::requeue($cb ? $cb : $arg); die '$end unsupported w/o $io' if $end; return; } diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm index d59320bc..b3fc5bef 100644 --- a/lib/PublicInbox/SolverGit.pm +++ b/lib/PublicInbox/SolverGit.pm @@ -327,7 +327,7 @@ sub do_finish ($$) { $user_cb->(undef); } -sub do_step ($) { +sub event_step ($) { my ($self) = @_; eval { # step 1: resolve blobs to patches in the todo queue @@ -366,10 +366,10 @@ sub do_step ($) { sub next_step ($) { my ($self) = @_; # if outside of public-inbox-httpd, caller is expected to be - # looping do_step, anyways + # looping event_step, anyways my $async = $self->{psgi_env}->{'pi-httpd.async'} or return; # PublicInbox::HTTPD::Async->new - $async->(undef, \&do_step, $self); + $async->(undef, undef, $self); } sub mark_found ($$$) { @@ -595,9 +595,9 @@ sub solve ($$$$$) { dbg($self, "solving $oid_want ..."); if (my $async = $env->{'pi-httpd.async'}) { # PublicInbox::HTTPD::Async->new - $async->(undef, \&do_step, $self); + $async->(undef, undef, $self); } else { - do_step($self) while $self->{user_cb}; + event_step($self) while $self->{user_cb}; } }