]> Sergey Matveev's repositories - public-inbox.git/commitdiff
qspawn: capture errors from parse_hdr callback
authorEric Wong <e@yhbt.net>
Mon, 30 Mar 2020 18:30:08 +0000 (18:30 +0000)
committerEric Wong <e@yhbt.net>
Mon, 30 Mar 2020 18:31:07 +0000 (18:31 +0000)
User-supplied callbacks may fail, so capture the error instead
of propagating it up the stack into the public-inbox-httpd event
loop.

lib/PublicInbox/Qspawn.pm

index 34b6912fea558dd01ee924f463e180f946fd26e1..aebcb1f7db091ea8d3283407a2c0cbd559d407f8 100644 (file)
@@ -234,7 +234,11 @@ sub rd_hdr ($) {
                                length($$hdr_buf));
                if (defined($r)) {
                        $total_rd += $r;
-                       $ret = $ph_cb->($total_rd, $hdr_buf, $ph_arg);
+                       eval { $ret = $ph_cb->($total_rd, $hdr_buf, $ph_arg) };
+                       if ($@) {
+                               log_err($self->{psgi_env}, "parse_hdr: $@");
+                               $ret = [ 500, [], [ "Internal error\n" ] ];
+                       }
                } else {
                        # caller should notify us when it's ready:
                        return if $! == EAGAIN;