]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
viewvcs: handle exceptions in on_destroy cb
authorEric Wong <e@80x24.org>
Fri, 24 Jan 2025 09:18:56 +0000 (09:18 +0000)
committerEric Wong <e@80x24.org>
Mon, 27 Jan 2025 21:53:05 +0000 (21:53 +0000)
We need to account for File::Temp->newdir or autodie::open
croaking on us in case the system is out of space or memory.
These resource errors are already handled in our normal code
path.  However, this on_destroy codepath can be triggered
when the solver request needs to be queued due to business.
Thus we explicitly call the {-wcb} to ensure the socket
isn't forgotten.

lib/PublicInbox/ViewVCS.pm

index 8d937cff0d8e188a62e3bc0f049207cb7bdd7537..96b60ee077ab72843fbd47ef44b8557a910ecddb 100644 (file)
@@ -648,6 +648,7 @@ sub start_solver ($) {
        }
        $ctx->{-next_solver} = on_destroy \&next_solver;
        ++$solver_nr;
+       # ->newdir and open may croak
        $ctx->{-tmp} = File::Temp->newdir("solver.$ctx->{oid_b}-XXXX",
                                                TMPDIR => 1);
        $ctx->{lh} or open $ctx->{lh}, '+>>', "$ctx->{-tmp}/solve.log";
@@ -660,11 +661,14 @@ sub start_solver ($) {
        $solver->solve(@$ctx{qw(env lh oid_b hints)});
 }
 
-# run the next solver job when done and DESTROY-ed
+# run the next solver job when done and DESTROY-ed (on_destroy cb)
 sub next_solver {
        --$solver_nr;
+       my $ctx = shift(@solver_q) // return;
        # XXX FIXME: client may've disconnected if it waited a long while
-       start_solver(shift(@solver_q) // return);
+       eval { start_solver($ctx) };
+       warn "W: start_solver: $@" if $@;
+       html_page($ctx, 500) if $ctx->{-wcb};
 }
 
 sub may_start_solver ($) {