]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/SolverGit.pm
msg_iter: provide means to stop using anonymous subs
[public-inbox.git] / lib / PublicInbox / SolverGit.pm
1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # "Solve" blobs which don't exist in git code repositories by
5 # searching inboxes for post-image blobs.
6
7 # this emits a lot of debugging/tracing information which may be
8 # publically viewed over HTTP(S).  Be careful not to expose
9 # local filesystem layouts in the process.
10 package PublicInbox::SolverGit;
11 use strict;
12 use warnings;
13 use File::Temp 0.19 ();
14 use Fcntl qw(SEEK_SET);
15 use PublicInbox::Git qw(git_unquote git_quote);
16 use PublicInbox::MsgIter qw(msg_iter msg_part_text);
17 use PublicInbox::Qspawn;
18 use PublicInbox::Tmpfile;
19 use URI::Escape qw(uri_escape_utf8);
20
21 # POSIX requires _POSIX_ARG_MAX >= 4096, and xargs is required to
22 # subtract 2048 bytes.  We also don't factor in environment variable
23 # headroom into this.
24 use POSIX qw(sysconf _SC_ARG_MAX);
25 my $ARG_SIZE_MAX = (sysconf(_SC_ARG_MAX) || 4096) - 2048;
26 my $OID_MIN = 7;
27
28 # By default, "git format-patch" generates filenames with a four-digit
29 # prefix, so that means 9999 patch series are OK, right? :>
30 # Maybe we can make this configurable, main concern is disk space overhead
31 # for uncompressed patch fragments.  Aside from space, public-inbox-httpd
32 # is otherwise unaffected by having many patches, here, as it can share
33 # work fairly.  Other PSGI servers may have trouble, though.
34 my $MAX_PATCH = 9999;
35
36 # di = diff info / a hashref with information about a diff ($di):
37 # {
38 #       oid_a => abbreviated pre-image oid,
39 #       oid_b => abbreviated post-image oid,
40 #       tmp => anonymous file handle with the diff,
41 #       hdr_lines => arrayref of various header lines for mode information
42 #       mode_a => original mode of oid_a (string, not integer),
43 #       ibx => PublicInbox::Inbox object containing the diff
44 #       smsg => PublicInbox::SearchMsg object containing diff
45 #       path_a => pre-image path
46 #       path_b => post-image path
47 #       n => numeric path of the patch (relative to worktree)
48 # }
49
50 # don't bother if somebody sends us a patch with these path components,
51 # it's junk at best, an attack attempt at worse:
52 my %bad_component = map { $_ => 1 } ('', '.', '..');
53
54 sub dbg ($$) {
55         print { $_[0]->{out} } $_[1], "\n" or ERR($_[0], "print(dbg): $!");
56 }
57
58 sub ERR ($$) {
59         my ($self, $err) = @_;
60         print { $self->{out} } $err, "\n";
61         my $ucb = delete($self->{user_cb});
62         eval { $ucb->($err) } if $ucb;
63         die $err;
64 }
65
66 # look for existing objects already in git repos
67 sub solve_existing ($$) {
68         my ($self, $want) = @_;
69         my $oid_b = $want->{oid_b};
70         my $have_hints = scalar keys %$want > 1;
71         my @ambiguous; # Array of [ git, $oids]
72         foreach my $git (@{$self->{gits}}) {
73                 my ($oid_full, $type, $size) = $git->check($oid_b);
74                 if (defined($type) && (!$have_hints || $type eq 'blob')) {
75                         return [ $git, $oid_full, $type, int($size) ];
76                 }
77
78                 next if length($oid_b) == 40;
79
80                 # parse stderr of "git cat-file --batch-check"
81                 my $err = $git->last_check_err;
82                 my (@oids) = ($err =~ /\b([a-f0-9]{40})\s+blob\b/g);
83                 next unless scalar(@oids);
84
85                 # TODO: do something with the ambiguous array?
86                 # push @ambiguous, [ $git, @oids ];
87
88                 dbg($self, "`$oid_b' ambiguous in " .
89                                 join("\n\t", $git->pub_urls($self->{psgi_env}))
90                                 . "\n" .
91                                 join('', map { "$_ blob\n" } @oids));
92         }
93         scalar(@ambiguous) ? \@ambiguous : undef;
94 }
95
96 sub extract_diff ($$) {
97         my ($p, $arg) = @_;
98         my ($self, $diffs, $re, $ibx, $smsg) = @$arg;
99         my ($part) = @$p; # ignore $depth and @idx;
100         my $hdr_lines; # diff --git a/... b/...
101         my $tmp;
102         my $ct = $part->content_type || 'text/plain';
103         my ($s, undef) = msg_part_text($part, $ct);
104         defined $s or return;
105         my $di = {};
106
107         # Email::MIME::Encodings forces QP to be CRLF upon decoding,
108         # change it back to LF:
109         my $cte = $part->header('Content-Transfer-Encoding') || '';
110         if ($cte =~ /\bquoted-printable\b/i && $part->crlf eq "\n") {
111                 $s =~ s/\r\n/\n/sg;
112         }
113
114         foreach my $l (split(/^/m, $s)) {
115                 if ($l =~ $re) {
116                         $di->{oid_a} = $1;
117                         $di->{oid_b} = $2;
118                         if (defined($3)) {
119                                 my $mode_a = $3;
120                                 if ($mode_a =~ /\A(?:100644|120000|100755)\z/) {
121                                         $di->{mode_a} = $mode_a;
122                                 }
123                         }
124
125
126                         # start writing the diff out to a tempfile
127                         my $path = ++$self->{tot};
128                         $di->{n} = $path;
129                         open($tmp, '>', $self->{tmp}->dirname . "/$path") or
130                                                         die "open(tmp): $!";
131
132                         push @$hdr_lines, $l;
133                         $di->{hdr_lines} = $hdr_lines;
134                         utf8::encode($_) for @$hdr_lines;
135                         print $tmp @$hdr_lines or die "print(tmp): $!";
136
137                         # for debugging/diagnostics:
138                         $di->{ibx} = $ibx;
139                         $di->{smsg} = $smsg;
140                 } elsif ($l =~ m!\Adiff --git ("?[^/]+/.+) ("?[^/]+/.+)$!) {
141                         last if $tmp; # got our blob, done!
142
143                         my ($path_a, $path_b) = ($1, $2);
144
145                         # diff header lines won't have \r because git
146                         # will quote them, but Email::MIME gives CRLF
147                         # for quoted-printable:
148                         $path_b =~ tr/\r//d;
149
150                         # don't care for leading 'a/' and 'b/'
151                         my (undef, @a) = split(m{/}, git_unquote($path_a));
152                         my (undef, @b) = split(m{/}, git_unquote($path_b));
153
154                         # get rid of path-traversal attempts and junk patches:
155                         foreach (@a, @b) {
156                                 return if $bad_component{$_};
157                         }
158
159                         $di->{path_a} = join('/', @a);
160                         $di->{path_b} = join('/', @b);
161                         $hdr_lines = [ $l ];
162                 } elsif ($tmp) {
163                         utf8::encode($l);
164                         print $tmp $l or die "print(tmp): $!";
165                 } elsif ($hdr_lines) {
166                         push @$hdr_lines, $l;
167                         if ($l =~ /\Anew file mode (100644|120000|100755)$/) {
168                                 $di->{mode_a} = $1;
169                         }
170                 }
171         }
172         return undef unless $tmp;
173         close $tmp or die "close(tmp): $!";
174         push @$diffs, $di;
175 }
176
177 sub path_searchable ($) { defined($_[0]) && $_[0] =~ m!\A[\w/\. \-]+\z! }
178
179 # ".." appears in path names, which confuses Xapian into treating
180 # it as a range query.  So we split on ".." since Xapian breaks
181 # on punctuation anyways:
182 sub filename_query ($) {
183         join('', map { qq( dfn:"$_") } split(/\.\./, $_[0]));
184 }
185
186 sub find_extract_diffs ($$$) {
187         my ($self, $ibx, $want) = @_;
188         my $srch = $ibx->search or return;
189
190         my $post = $want->{oid_b} or die 'BUG: no {oid_b}';
191         $post =~ /\A[a-f0-9]+\z/ or die "BUG: oid_b not hex: $post";
192
193         my $q = "dfpost:$post";
194         my $pre = $want->{oid_a};
195         if (defined $pre && $pre =~ /\A[a-f0-9]+\z/) {
196                 $q .= " dfpre:$pre";
197         } else {
198                 $pre = '[a-f0-9]{7}'; # for $re below
199         }
200
201         my $path_b = $want->{path_b};
202         if (path_searchable($path_b)) {
203                 $q .= filename_query($path_b);
204
205                 my $path_a = $want->{path_a};
206                 if (path_searchable($path_a) && $path_a ne $path_b) {
207                         $q .= filename_query($path_a);
208                 }
209         }
210
211         my $msgs = $srch->query($q, { relevance => 1 });
212         my $re = qr/\Aindex ($pre[a-f0-9]*)\.\.($post[a-f0-9]*)(?: ([0-9]+))?/;
213         my $diffs = [];
214         foreach my $smsg (@$msgs) {
215                 $ibx->smsg_mime($smsg) or next;
216                 my $mime = delete $smsg->{mime};
217                 msg_iter($mime, \&extract_diff,
218                                 [$self, $diffs, $re, $ibx, $smsg]);
219         }
220         @$diffs ? $diffs : undef;
221 }
222
223 sub update_index_result ($$) {
224         my ($bref, $self) = @_;
225         my ($qsp, $msg) = delete @$self{qw(-qsp -msg)};
226         if (my $err = $qsp->{err}) {
227                 ERR($self, "git update-index error: $err");
228         }
229         dbg($self, $msg);
230         next_step($self); # onto do_git_apply
231 }
232
233 sub prepare_index ($) {
234         my ($self) = @_;
235         my $patches = $self->{patches};
236         $self->{nr} = 0;
237
238         my $di = $patches->[0] or die 'no patches';
239         my $oid_a = $di->{oid_a} or die '{oid_a} unset';
240         my $existing = $self->{found}->{$oid_a};
241
242         # no index creation for added files
243         $oid_a =~ /\A0+\z/ and return next_step($self);
244
245         die "BUG: $oid_a not not found" unless $existing;
246
247         my $oid_full = $existing->[1];
248         my $path_a = $di->{path_a} or die "BUG: path_a missing for $oid_full";
249         my $mode_a = $di->{mode_a} || extract_old_mode($di);
250
251         my $in = tmpfile("update-index.$oid_full") or die "tmpfile: $!";
252         print $in "$mode_a $oid_full\t$path_a\0" or die "print: $!";
253         $in->flush or die "flush: $!";
254         sysseek($in, 0, 0) or die "seek: $!";
255
256         dbg($self, 'preparing index');
257         my $rdr = { 0 => fileno($in), -hold => $in };
258         my $cmd = [ qw(git update-index -z --index-info) ];
259         my $qsp = PublicInbox::Qspawn->new($cmd, $self->{git_env}, $rdr);
260         $path_a = git_quote($path_a);
261         $self->{-qsp} = $qsp;
262         $self->{-msg} = "index prepared:\n$mode_a $oid_full\t$path_a";
263         $qsp->psgi_qx($self->{psgi_env}, undef, \&update_index_result, $self);
264 }
265
266 # pure Perl "git init"
267 sub do_git_init ($) {
268         my ($self) = @_;
269         my $dir = $self->{tmp}->dirname;
270         my $git_dir = "$dir/git";
271
272         foreach ('', qw(objects refs objects/info refs/heads)) {
273                 mkdir("$git_dir/$_") or die "mkdir $_: $!";
274         }
275         open my $fh, '>', "$git_dir/config" or die "open git/config: $!";
276         print $fh <<'EOF' or die "print git/config $!";
277 [core]
278         repositoryFormatVersion = 0
279         filemode = true
280         bare = false
281         fsyncObjectfiles = false
282         logAllRefUpdates = false
283 EOF
284         close $fh or die "close git/config: $!";
285
286         open $fh, '>', "$git_dir/HEAD" or die "open git/HEAD: $!";
287         print $fh "ref: refs/heads/master\n" or die "print git/HEAD: $!";
288         close $fh or die "close git/HEAD: $!";
289
290         my $f = 'objects/info/alternates';
291         open $fh, '>', "$git_dir/$f" or die "open: $f: $!";
292         foreach my $git (@{$self->{gits}}) {
293                 print $fh $git->git_path('objects'),"\n" or die "print $f: $!";
294         }
295         close $fh or die "close: $f: $!";
296         my $tmp_git = $self->{tmp_git} = PublicInbox::Git->new($git_dir);
297         $tmp_git->{-tmp} = $self->{tmp};
298         $self->{git_env} = {
299                 GIT_DIR => $git_dir,
300                 GIT_INDEX_FILE => "$git_dir/index",
301         };
302         prepare_index($self);
303 }
304
305 sub extract_old_mode ($) {
306         my ($di) = @_;
307         if (join('', @{$di->{hdr_lines}}) =~
308                         /^old mode (100644|100755|120000)\b/) {
309                 return $1;
310         }
311         '100644';
312 }
313
314 sub do_finish ($$) {
315         my ($self, $user_cb) = @_;
316         my $found = $self->{found};
317         my $oid_want = $self->{oid_want};
318         if (my $exists = $found->{$oid_want}) {
319                 return $user_cb->($exists);
320         }
321
322         # let git disambiguate if oid_want was too short,
323         # but long enough to be unambiguous:
324         my $tmp_git = $self->{tmp_git};
325         if (my @res = $tmp_git->check($oid_want)) {
326                 return $user_cb->($found->{$res[0]});
327         }
328         if (my $err = $tmp_git->last_check_err) {
329                 dbg($self, $err);
330         }
331         $user_cb->(undef);
332 }
333
334 sub event_step ($) {
335         my ($self) = @_;
336         eval {
337                 # step 1: resolve blobs to patches in the todo queue
338                 if (my $want = pop @{$self->{todo}}) {
339                         # this populates {patches} and {todo}
340                         resolve_patch($self, $want);
341
342                 # step 2: then we instantiate a working tree once
343                 # the todo queue is finally empty:
344                 } elsif (!defined($self->{tmp_git})) {
345                         do_git_init($self);
346
347                 # step 3: apply each patch in the stack
348                 } elsif (scalar @{$self->{patches}}) {
349                         do_git_apply($self);
350
351                 # step 4: execute the user-supplied callback with
352                 # our result: (which may be undef)
353                 # Other steps may call user_cb to terminate prematurely
354                 # on error
355                 } elsif (my $user_cb = delete($self->{user_cb})) {
356                         do_finish($self, $user_cb);
357                 } else {
358                         die 'about to call user_cb twice'; # Oops :x
359                 }
360         }; # eval
361         my $err = $@;
362         if ($err) {
363                 $err =~ s/^\s*Exception:\s*//; # bad word to show users :P
364                 dbg($self, "E: $err");
365                 my $ucb = delete($self->{user_cb});
366                 eval { $ucb->($err) } if $ucb;
367         }
368 }
369
370 sub next_step ($) {
371         my ($self) = @_;
372         # if outside of public-inbox-httpd, caller is expected to be
373         # looping event_step, anyways
374         my $async = $self->{psgi_env}->{'pi-httpd.async'} or return;
375         # PublicInbox::HTTPD::Async->new
376         $async->(undef, undef, $self);
377 }
378
379 sub mark_found ($$$) {
380         my ($self, $oid, $found_info) = @_;
381         my $found = $self->{found};
382         $found->{$oid} = $found_info;
383         my $oid_cur = $found_info->[1];
384         while ($oid_cur ne $oid && length($oid_cur) > $OID_MIN) {
385                 $found->{$oid_cur} = $found_info;
386                 chop($oid_cur);
387         }
388 }
389
390 sub parse_ls_files ($$) {
391         my ($self, $bref) = @_;
392         my ($qsp, $di) = delete @$self{qw(-qsp -cur_di)};
393         if (my $err = $qsp->{err}) {
394                 die "git ls-files error: $err";
395         }
396
397         my ($line, @extra) = split(/\0/, $$bref);
398         scalar(@extra) and die "BUG: extra files in index: <",
399                                 join('> <', @extra), ">";
400
401         my ($info, $file) = split(/\t/, $line, 2);
402         my ($mode_b, $oid_b_full, $stage) = split(/ /, $info);
403         if ($file ne $di->{path_b}) {
404                 die
405 "BUG: index mismatch: file=$file != path_b=$di->{path_b}";
406         }
407
408         my $tmp_git = $self->{tmp_git} or die 'no git working tree';
409         my (undef, undef, $size) = $tmp_git->check($oid_b_full);
410         defined($size) or die "check $oid_b_full failed";
411
412         dbg($self, "index at:\n$mode_b $oid_b_full\t$file");
413         my $created = [ $tmp_git, $oid_b_full, 'blob', $size, $di ];
414         mark_found($self, $di->{oid_b}, $created);
415         next_step($self); # onto the next patch
416 }
417
418 sub ls_files_result {
419         my ($bref, $self) = @_;
420         eval { parse_ls_files($self, $bref) };
421         ERR($self, $@) if $@;
422 }
423
424 sub oids_same_ish ($$) {
425         (index($_[0], $_[1]) == 0) || (index($_[1], $_[0]) == 0);
426 }
427
428 sub skip_identical ($$$) {
429         my ($self, $patches, $cur_oid_b) = @_;
430         while (my $nxt = $patches->[0]) {
431                 if (oids_same_ish($cur_oid_b, $nxt->{oid_b})) {
432                         dbg($self, 'skipping '.di_url($self, $nxt).
433                                 " for $cur_oid_b");
434                         shift @$patches;
435                 } else {
436                         return;
437                 }
438         }
439 }
440
441 sub apply_result ($$) {
442         my ($bref, $self) = @_;
443         my ($qsp, $di) = delete @$self{qw(-qsp -cur_di)};
444         dbg($self, $$bref);
445         my $patches = $self->{patches};
446         if (my $err = $qsp->{err}) {
447                 my $msg = "git apply error: $err";
448                 my $nxt = $patches->[0];
449                 if ($nxt && oids_same_ish($nxt->{oid_b}, $di->{oid_b})) {
450                         dbg($self, $msg);
451                         dbg($self, 'trying '.di_url($self, $nxt));
452                 } else {
453                         ERR($self, $msg);
454                 }
455         } else {
456                 skip_identical($self, $patches, $di->{oid_b});
457         }
458
459         my @cmd = qw(git ls-files -s -z);
460         $qsp = PublicInbox::Qspawn->new(\@cmd, $self->{git_env});
461         $self->{-cur_di} = $di;
462         $self->{-qsp} = $qsp;
463         $qsp->psgi_qx($self->{psgi_env}, undef, \&ls_files_result, $self);
464 }
465
466 sub do_git_apply ($) {
467         my ($self) = @_;
468         my $dn = $self->{tmp}->dirname;
469         my $patches = $self->{patches};
470
471         # we need --ignore-whitespace because some patches are CRLF
472         my @cmd = (qw(git -C), $dn, qw(apply --cached --ignore-whitespace
473                         --unidiff-zero --whitespace=warn --verbose));
474         my $len = length(join(' ', @cmd));
475         my $total = $self->{tot};
476         my $di; # keep track of the last one for "git ls-files"
477         my $prv_oid_b;
478
479         do {
480                 my $i = ++$self->{nr};
481                 $di = shift @$patches;
482                 dbg($self, "\napplying [$i/$total] " . di_url($self, $di) .
483                         "\n" . join('', @{$di->{hdr_lines}}));
484                 my $path = $di->{n};
485                 $len += length($path) + 1;
486                 push @cmd, $path;
487                 $prv_oid_b = $di->{oid_b};
488         } while (@$patches && $len < $ARG_SIZE_MAX &&
489                  !oids_same_ish($patches->[0]->{oid_b}, $prv_oid_b));
490
491         my $rdr = { 2 => 1 };
492         my $qsp = PublicInbox::Qspawn->new(\@cmd, $self->{git_env}, $rdr);
493         $self->{-cur_di} = $di;
494         $self->{-qsp} = $qsp;
495         $qsp->psgi_qx($self->{psgi_env}, undef, \&apply_result, $self);
496 }
497
498 sub di_url ($$) {
499         my ($self, $di) = @_;
500         # note: we don't pass the PSGI env unconditionally, here,
501         # different inboxes can have different HTTP_HOST on the same instance.
502         my $ibx = $di->{ibx};
503         my $env = $self->{psgi_env} if $ibx eq $self->{inboxes}->[0];
504         my $url = $ibx->base_url($env);
505         my $mid = $di->{smsg}->{mid};
506         defined($url) ? "$url$mid/" : "<$mid>";
507 }
508
509 sub resolve_patch ($$) {
510         my ($self, $want) = @_;
511
512         if (scalar(@{$self->{patches}}) > $MAX_PATCH) {
513                 die "Aborting, too many steps to $self->{oid_want}";
514         }
515
516         # see if we can find the blob in an existing git repo:
517         my $cur_want = $want->{oid_b};
518         if ($self->{seen_oid}->{$cur_want}++) {
519                 die "Loop detected solving $cur_want\n";
520         }
521         if (my $existing = solve_existing($self, $want)) {
522                 my ($found_git, undef, $type, undef) = @$existing;
523                 dbg($self, "found $cur_want in " .
524                         join("\n", $found_git->pub_urls($self->{psgi_env})));
525
526                 if ($cur_want eq $self->{oid_want} || $type ne 'blob') {
527                         eval { delete($self->{user_cb})->($existing) };
528                         die "E: $@" if $@;
529                         return;
530                 }
531                 mark_found($self, $cur_want, $existing);
532                 return next_step($self); # onto patch application
533         }
534
535         # scan through inboxes to look for emails which results in
536         # the oid we want:
537         foreach my $ibx (@{$self->{inboxes}}) {
538                 my $diffs = find_extract_diffs($self, $ibx, $want) or next;
539
540                 unshift @{$self->{patches}}, @$diffs;
541                 dbg($self, "found $cur_want in ".
542                         join("\n\t", map { di_url($self, $_) } @$diffs));
543
544                 # good, we can find a path to the oid we $want, now
545                 # lets see if we need to apply more patches:
546                 my $di = $diffs->[0];
547                 my $src = $di->{oid_a};
548
549                 unless ($src =~ /\A0+\z/) {
550                         # we have to solve it using another oid, fine:
551                         my $job = { oid_b => $src, path_b => $di->{path_a} };
552                         push @{$self->{todo}}, $job;
553                 }
554                 return next_step($self); # onto the next todo item
555         }
556         if (length($cur_want) > $OID_MIN) {
557                 chop($cur_want);
558                 dbg($self, "retrying $want->{oid_b} as $cur_want");
559                 $want->{oid_b} = $cur_want;
560                 push @{$self->{todo}}, $want;
561                 return next_step($self); # retry with shorter abbrev
562         }
563
564         dbg($self, "could not find $cur_want");
565         eval { delete($self->{user_cb})->(undef) }; # not found! :<
566         die "E: $@" if $@;
567 }
568
569 # this API is designed to avoid creating self-referential structures;
570 # so user_cb never references the SolverGit object
571 sub new {
572         my ($class, $ibx, $user_cb) = @_;
573
574         bless {
575                 gits => $ibx->{-repo_objs},
576                 user_cb => $user_cb,
577                 # -cur_di, -qsp, -msg => temporary fields for Qspawn callbacks
578
579                 # TODO: config option for searching related inboxes
580                 inboxes => [ $ibx ],
581         }, $class;
582 }
583
584 # recreate $oid_want using $hints
585 # hints keys: path_a, path_b, oid_a
586 # Calls {user_cb} with: [ ::Git object, oid_full, type, size, di (diff_info) ]
587 # with found object, or undef if nothing was found
588 # Calls {user_cb} with a string error on fatal errors
589 sub solve ($$$$$) {
590         my ($self, $env, $out, $oid_want, $hints) = @_;
591
592         # should we even get here? Probably not, but somebody
593         # could be manually typing URLs:
594         return (delete $self->{user_cb})->(undef) if $oid_want =~ /\A0+\z/;
595
596         $self->{oid_want} = $oid_want;
597         $self->{out} = $out;
598         $self->{seen_oid} = {};
599         $self->{tot} = 0;
600         $self->{psgi_env} = $env;
601         $self->{todo} = [ { %$hints, oid_b => $oid_want } ];
602         $self->{patches} = []; # [ $di, $di, ... ]
603         $self->{found} = {}; # { abbr => [ ::Git, oid, type, size, $di ] }
604         $self->{tmp} = File::Temp->newdir("solver.$oid_want-XXXXXXXX", TMPDIR => 1);
605
606         dbg($self, "solving $oid_want ...");
607         if (my $async = $env->{'pi-httpd.async'}) {
608                 # PublicInbox::HTTPD::Async->new
609                 $async->(undef, undef, $self);
610         } else {
611                 event_step($self) while $self->{user_cb};
612         }
613 }
614
615 1;