]> git.ipfire.org Git - thirdparty/public-inbox.git/log
thirdparty/public-inbox.git
20 months agolei_xsearch: put query in process title for debugging
Eric Wong [Thu, 9 Nov 2023 10:09:34 +0000 (10:09 +0000)] 
lei_xsearch: put query in process title for debugging

Having queries in the process titles makes it easier to diagnose
stuck queries due to IPC problems.  This was used to diagnose
commit e97a30e7624d (lei: fix SIGPIPE on large result sets to pager)).

20 months agolei: fix SIGPIPE on large result sets to pager
Eric Wong [Tue, 7 Nov 2023 13:01:47 +0000 (13:01 +0000)] 
lei: fix SIGPIPE on large result sets to pager

When dealing with large search results, we need to deal with
EPIPE not just from the pager, but also EPIPE or ECONNRESET
between lei_xsearch and lei2mail processes.

Without this fix, lei_xsearch processes could linger and get
stuck writing to dead lei2mail processes if a user aborts the
pager early during a large result set.

To ensure lei_xsearch processes don't linger around after
lei2mail workers all die, we must close $l2m->{-wq_s2} before
spawning lei_xsearch processes, since $l2m->{-wq_s2} is only
used in lei2mail workers.

For `git cat-file' processes, we also need to trigger
PublicInbox::Git->close to handle unpredictable destructor
ordering to avoid using uninitialized IO refs.  This combines
with the `git_to_mail' change to deal with process cleanup
handling from premature shutdowns.

To test all this, we can't just rely on a single message being
large, but also need to rely on the result set being large
enough to saturate the lei_xsearch -> lei2mail socket so we
rely on GIANT_INBOX_DIR once again.

20 months agolei_view_text: fix inverted condition
Eric Wong [Fri, 3 Nov 2023 20:25:07 +0000 (20:25 +0000)] 
lei_view_text: fix inverted condition

This was causing `lei q -f text' output to be uncolored on
color-capable terminals.

Fixes: d3c55d072839 (treewide: use ->close to call ProcessIO->CLOSE)
20 months agot/cindex+extsearch: use write_file, autodie, etc.
Eric Wong [Thu, 2 Nov 2023 09:35:39 +0000 (09:35 +0000)] 
t/cindex+extsearch: use write_file, autodie, etc.

write_file is a new API which makes setting up config files more
pleasant, while autodie and scalarref redirects (in tests) have
been available for a while, now.  So do what we can to reduce
the code burden we have.

20 months agomove read_all, try_cat, and poll_in to PublicInbox::IO
Eric Wong [Thu, 2 Nov 2023 09:35:38 +0000 (09:35 +0000)] 
move read_all, try_cat, and poll_in to PublicInbox::IO

The IO package seems like a better home for I/O subs than the
Git package.  We lose the 60 second read timeout for `git
cat-file --batch-*' processes since it's probably not necessary
given how reliable the code has proven and things would fall
over hard in other ways if the storage device were completely
hosed.

20 months agotreewide: use eof and close to detect readline errors
Eric Wong [Thu, 2 Nov 2023 09:35:37 +0000 (09:35 +0000)] 
treewide: use eof and close to detect readline errors

readline (<FH>) isn't wrapped by autodie, and there's no
way to know if read(2) errors truncated the readline output.
IO::Handle->error isn't reliable on Perl < v5.34.

Thus, combining the `eof' and `close' (combined with autodie) is
the only way we can detect read(2) errors (injected via strace)
when called via `readline' (aka <$fh>).  Neither using `eof'
nor `close' alone is sufficient, they must be combined to detect
errors from buffered `readline'.

20 months agotreewide: check alternates writes with eof + autodie
Eric Wong [Thu, 2 Nov 2023 09:35:36 +0000 (09:35 +0000)] 
treewide: check alternates writes with eof + autodie

We must use eof() combined with close() to detect errors
in situations involving the readline()' op since `readline'
(and most buffered I/O libraries) have weak error detection
support.

This fixes error detection for files opened for read/write
access.  The next commit will fix error detection for read-only
files.

20 months agospawn: support PerlIO layer in scalar redirects
Eric Wong [Thu, 2 Nov 2023 09:35:35 +0000 (09:35 +0000)] 
spawn: support PerlIO layer in scalar redirects

We have to deal with UTF-8 data for generating patches, so make
it easier to pass Perl utf8 data to git, diff, sdiff, etc. to
avoid "Wide character" warnings.

20 months agoio: introduce write_file helper sub
Eric Wong [Thu, 2 Nov 2023 09:35:34 +0000 (09:35 +0000)] 
io: introduce write_file helper sub

This is pretty convenient way to create files for diff
generation in both WWW and lei.  The test suite should also be
able to take advantage of it.

20 months agoreplace ProcessIO with untied PublicInbox::IO
Eric Wong [Thu, 2 Nov 2023 09:35:33 +0000 (09:35 +0000)] 
replace ProcessIO with untied PublicInbox::IO

This fixes two major problems with the use of tie for filehandles:

* no way to do fcntl, stat, etc. calls directly on the tied handle,
  forcing callers to use the `tied' perlop to access the underlying
  IO::Handle

* needing separate classes to handle blocking and non-blocking I/O

As a result, Git->cleanup_if_unlinked, InputPipe->consume,
and Qspawn->_yield_start have fewer bizzare bits and we
can call `$io->blocking(0)' directly instead of
`(tied *$io)->{fh}->blocking(0)'

Having a PublicInbox::IO class will also allow us to support
custom read buffering which allows inspecting the current state.

20 months agogit_credential: use autodie where appropriate
Eric Wong [Thu, 2 Nov 2023 09:35:32 +0000 (09:35 +0000)] 
git_credential: use autodie where appropriate

We can also rely on `say' in Perl 5.10+ to save us the trouble
of printing a newline.

20 months agomulti_git: use autodie
Eric Wong [Thu, 2 Nov 2023 09:35:31 +0000 (09:35 +0000)] 
multi_git: use autodie

Trying to move away from half my code being "or die" statements...

20 months agotreewide: use ->close to call ProcessIO->CLOSE
Eric Wong [Thu, 2 Nov 2023 09:35:30 +0000 (09:35 +0000)] 
treewide: use ->close to call ProcessIO->CLOSE

This will open the door for us to drop `tie' usage from
ProcessIO completely in favor of OO method dispatch.  While
OO method dispatches (e.g. `$fh->close') are slower than normal
subroutine calls, it hardly matters in this case since process
teardown is a fairly rare operation and we continue to use
`close($fh)' for Maildir writes.

20 months agocindex: drop redundant close on regular FH
Eric Wong [Thu, 2 Nov 2023 09:35:29 +0000 (09:35 +0000)] 
cindex: drop redundant close on regular FH

There's no need to waste optree space on close() statements for
file handles which are (effectively) read-only on their last use
and incapable of error checking in our Perl code (since they're
only read by git).

Let Perl refcounting take care of it so we have less code to
wade through when focusing on `close' statements which actually
matter.

20 months agods: don't try ->close after ->accept_SSL failure
Eric Wong [Thu, 2 Nov 2023 21:35:50 +0000 (21:35 +0000)] 
ds: don't try ->close after ->accept_SSL failure

Eric Wong <e@80x24.org> wrote:
> --- a/lib/PublicInbox/DS.pm
> +++ b/lib/PublicInbox/DS.pm
> @@ -341,8 +341,8 @@ sub greet {
>   my $ev = EPOLLIN;
>   my $wbuf;
>   if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
> - return CORE::close($sock) if $! != EAGAIN;
> - $ev = PublicInbox::TLS::epollbit() or return CORE::close($sock);
> + return $sock->close if $! != EAGAIN;
> + $ev = PublicInbox::TLS::epollbit() or return $sock->close;
>   $wbuf = [ \&accept_tls_step, $self->can('do_greet')];
>   }
>   new($self, $sock, $ev | EPOLLONESHOT);

Noticed this on deploy:

-----8<-----
Subject: [PATCH] ds: don't try ->close after ->accept_SSL failure

->accept_SSL failures leaves the socket ref as a GLOB (not
IO::Handle) and unable to respond to the ->close method.
Calling close in any form isn't actually necessary at all,
so just let refcounting destroy the socket.

20 months agotreewide: use ->close method rather than CORE::close
Eric Wong [Thu, 2 Nov 2023 09:35:28 +0000 (09:35 +0000)] 
treewide: use ->close method rather than CORE::close

It's easier-to-read and should open the door for us to get rid
of `tie' for ProcessIO without performance penalties for
more frequently-used perlop calls and ability to do `stat' directly
on the object instead of the awkward `tied' thing.

20 months agods: replace FD map hash table with array
Eric Wong [Thu, 2 Nov 2023 09:35:27 +0000 (09:35 +0000)] 
ds: replace FD map hash table with array

FDs are array indices into the kernel, anyways, so we can
take advantage of space savings and speedups because the
majority of FDs a big process has is going to end up in
the array, anyways.

20 months agoxap_helper.pm: use do_fork to Reset and reseed
Eric Wong [Thu, 2 Nov 2023 09:35:26 +0000 (09:35 +0000)] 
xap_helper.pm: use do_fork to Reset and reseed

We may start using rand() in the worker someday if we need
to seed a hash function for caching.  It saves us some LoC
in the meantime.

20 months agogit: reschedule cleanup if active
Eric Wong [Wed, 1 Nov 2023 06:31:48 +0000 (06:31 +0000)] 
git: reschedule cleanup if active

This is necessary to reliably cleanup cat-file processes for
coderepos in long-lived -netd and -httpd processes if they
haven't been accessed in a while.

Followup-to: 33e99002c552 (git: cleanup un-associated coderepo processes)
20 months agods: make ->close behave like CORE::close
Eric Wong [Tue, 31 Oct 2023 20:42:55 +0000 (20:42 +0000)] 
ds: make ->close behave like CORE::close

Matching existing Perl IO semantics seems like a good idea to
reduce confusion in the future.

We'll also fix some outdated comments and update indentation
to match the rest of our code base since we're far detached from
Danga::Socket at this point.

20 months agopop3: use SSL_shutdown(3ssl) if appropriate
Eric Wong [Tue, 31 Oct 2023 20:42:54 +0000 (20:42 +0000)] 
pop3: use SSL_shutdown(3ssl) if appropriate

This allows us support SSL session caching + reuse in the future.

20 months agowatch: simplify DirIdle object cleanup
Eric Wong [Tue, 31 Oct 2023 20:42:53 +0000 (20:42 +0000)] 
watch: simplify DirIdle object cleanup

There's no need to waste time nor reach into DS internals to
map FDs to Perl objects, here.  LEI.pm has never had to deal
with integer FDs for DirIdle, either.

20 months agods: move maxevents further down the stack
Eric Wong [Tue, 31 Oct 2023 20:42:52 +0000 (20:42 +0000)] 
ds: move maxevents further down the stack

The epoll implementation is the only one which respects the
limit (kevent would, but IO::KQueue does not).  In any case,
I'm not a fan of the maxevents=1000 historical default since
it leads to fairness problems with shared non-blocking listeners
across multiple daemon workers.

20 months agods: do not defer close
Eric Wong [Tue, 31 Oct 2023 20:42:51 +0000 (20:42 +0000)] 
ds: do not defer close

We can map all integer FDs to Perl objects once ->ep_wait returns,
so there's no need to play tricks elsewhere to ensure FDs can
be mapped to objects within the same event loop iteration.

20 months agods: next_tick: shorten object lifetimes
Eric Wong [Tue, 31 Oct 2023 20:42:50 +0000 (20:42 +0000)] 
ds: next_tick: shorten object lifetimes

Drop reference counts ASAP in case it saves us some memory
sooner rather than later.  This ought to give us more predictable
resource use and ensure OnDestroy callbacks fire sooner.
There's no need to use `local' to clobber the arrayref anymore,
either.

AFAIK, this doesn't fix any known bug, but more predictability
will make it easier to debug things going forward.

20 months agoxap_helper.pm: quiet undefined die at shutdown
Eric Wong [Tue, 31 Oct 2023 20:34:51 +0000 (20:34 +0000)] 
xap_helper.pm: quiet undefined die at shutdown

Another attempt at doing what commit 35de8fdcbf290e25
(xap_helper.pm: quiet undefined warnings at shutdown, 2023-10-23)
tried to do.  It turns out perl croaks (not warn/carp) when it sees
an undefined file handle, here.

20 months agopoll+select: check EBADF + POLLNVAL errors
Eric Wong [Mon, 30 Oct 2023 18:29:40 +0000 (18:29 +0000)] 
poll+select: check EBADF + POLLNVAL errors

I hit this in via select running -cindex with some other
experimental patches.  I can't reproduce the problem, though,
but this ensure we have a chance to diagnose it if it happens
again instead of looping on select(2) => EBADF.

20 months agolei_config: import read_all properly
Eric Wong [Sun, 29 Oct 2023 16:08:06 +0000 (16:08 +0000)] 
lei_config: import read_all properly

*sigh* fixing interactive editing stuff is a pain...
Found while making other changes...

Fixes: 19b791f4894efcb6 (use read_all in more places to improve safety)
20 months agolei_mirror: fix seek/sysseek argument ordering
Eric Wong [Sun, 29 Oct 2023 05:56:32 +0000 (05:56 +0000)] 
lei_mirror: fix seek/sysseek argument ordering

It doesn't matter in practice for platforms we support, since
SEEK_SET is `0' everywhere I've seen.

20 months agoexamples/logrotate: only SIGUSR1 main process
Eric Wong [Sat, 28 Oct 2023 18:01:13 +0000 (18:01 +0000)] 
examples/logrotate: only SIGUSR1 main process

There's no need to send SIGUSR1 to auxiliary processes since
they don't know what to do with them.

20 months agoexamples/*.service: avoid `nobody' user on systemd
Eric Wong [Sat, 28 Oct 2023 18:01:12 +0000 (18:01 +0000)] 
examples/*.service: avoid `nobody' user on systemd

systemd complains about `User=nobody' since `nobody' has access
to all files which can't be mapped to a valid UID.  We'll also
switch to `Group=ssl-cert' since that ought to be able to read
TLS certificates.

21 months agospawn: use readline instead of read for scalar redirects
Eric Wong [Sat, 28 Oct 2023 09:12:43 +0000 (09:12 +0000)] 
spawn: use readline instead of read for scalar redirects

Using `-s $fh' as the length arg for `read' is incorrect for
:utf8 and other non-:raw file handles because `read' operates
in *characters*, not bytes.

21 months agolei_ale: use v5.12, autodie, and try_cat
Eric Wong [Fri, 27 Oct 2023 22:21:16 +0000 (22:21 +0000)] 
lei_ale: use v5.12, autodie, and try_cat

Just things I spotted while looking for other problems
throughout our codebase.

21 months agoxt/eml_check_limits: remove useless import
Eric Wong [Fri, 27 Oct 2023 22:21:15 +0000 (22:21 +0000)] 
xt/eml_check_limits: remove useless import

Found while hunting for popen_rd calls.

21 months agowww_altid: reduce FD pressure in qspawn queues
Eric Wong [Fri, 27 Oct 2023 22:21:14 +0000 (22:21 +0000)] 
www_altid: reduce FD pressure in qspawn queues

We can use the built-in stdin redirection functionality of
spawn() instead of creating a pipe that sits idle in the queue
on busy servers.

21 months agotreewide: use run_qx where appropriate
Eric Wong [Fri, 27 Oct 2023 22:21:13 +0000 (22:21 +0000)] 
treewide: use run_qx where appropriate

This saves us some code, and is a small step towards getting
ProcessIO working with stat, fcntl and other perlops that don't
work with tied handles.

21 months agogcf2: simplify pkg-config and Inline::C setup
Eric Wong [Fri, 27 Oct 2023 22:21:12 +0000 (22:21 +0000)] 
gcf2: simplify pkg-config and Inline::C setup

We can use run_qx and try_cat to make the build setup simpler.

21 months agogit: avoid extra stat(2) for git version
Eric Wong [Fri, 27 Oct 2023 22:21:11 +0000 (22:21 +0000)] 
git: avoid extra stat(2) for git version

No sane installer will update executable files in place due to
ETXTBSY on execve.  So save ourselves a stat(2) call by relying
on the special `CORE::stat(_)' case to reuse the cached result
from the `-x FILE' filetest in which().

21 months agogit: use run_qx to read `git --version'
Eric Wong [Fri, 27 Oct 2023 22:21:10 +0000 (22:21 +0000)] 
git: use run_qx to read `git --version'

It exists, now, so save us a few lines of code.

21 months agospawn: avoid alloca in C pi_fork_exec
Eric Wong [Fri, 27 Oct 2023 22:21:09 +0000 (22:21 +0000)] 
spawn: avoid alloca in C pi_fork_exec

We don't have thread-safety to worry about, so just leave a few
allocations at process exit at worst.  We'll also update some
comments about usage while we're at it.

21 months agospawnpp: use autodie for syscall failures
Eric Wong [Fri, 27 Oct 2023 22:21:08 +0000 (22:21 +0000)] 
spawnpp: use autodie for syscall failures

We lose a little info for fork failures, but I don't think it
matters.

21 months agospawn: croak directly in C pi_fork_exec
Eric Wong [Fri, 27 Oct 2023 22:21:07 +0000 (22:21 +0000)] 
spawn: croak directly in C pi_fork_exec

This saves us some Perl code in the wrapper, since the SpawnPP
implementation also dies directly.

21 months agolei: don't exit lei-daemon on ovv_begin failure
Eric Wong [Fri, 27 Oct 2023 01:14:35 +0000 (01:14 +0000)] 
lei: don't exit lei-daemon on ovv_begin failure

When ->ovv_begin is called in LeiXSearch->do_query in the top-level
lei-daemon process, $lei->{pkt_op_p} still exists.  We must make
sure we're exiting the correct process since lei->out can call
lei->fail and lei->fail calls lei->x_it.

As to avoiding how I caused ->ovv_begin failures to begin with,
that's for a much bigger change...

21 months agocindex: clarify fatal vs non-fatal messages
Eric Wong [Thu, 26 Oct 2023 08:20:07 +0000 (08:20 +0000)] 
cindex: clarify fatal vs non-fatal messages

cindex must be able to handle coderepos being deleted mid-run
since `public-inbox-clone --purge' may be running at the same
time.  This is a step towards handling parallel invocations
of -cindex and public-inbox-clone as gracefully as possible
by improving error messages.

21 months agogit: cleanup un-associated coderepo processes
Eric Wong [Thu, 26 Oct 2023 08:20:06 +0000 (08:20 +0000)] 
git: cleanup un-associated coderepo processes

It's possible to have many coderepos with no inbox association
that never see git->cleanup.  So instead of tying git->cleanup
to inboxes, ensure it gets armed when ->watch_async is called
(since it's only called in our -netd or -httpd servers).

21 months agocindex: fix large prunes
Eric Wong [Wed, 25 Oct 2023 15:33:49 +0000 (15:33 +0000)] 
cindex: fix large prunes

When comm(1) has a lot of data to output, we must ensure we
explicitly close FDs of processes in previous stages of the
pipeline to ensure comm(1) to terminates properly.

This is difficult to test automatically with small test repos...

Fixes: 17b06aa32aac (cindex: start using run_await to simplify code)
21 months agocindex: quiet --prune when checking objectFormat
Eric Wong [Wed, 25 Oct 2023 15:33:48 +0000 (15:33 +0000)] 
cindex: quiet --prune when checking objectFormat

Most coderepos don't have extensions.objectFormat set,
so it's senseless to emit warnings on failures.

Fixes: 709fcf00c4d5 (cindex: use run_await to read extensions.objectFormat)
21 months agocindex: store coderepo data asynchronously
Eric Wong [Wed, 25 Oct 2023 15:33:47 +0000 (15:33 +0000)] 
cindex: store coderepo data asynchronously

While it's typically fast to store coderepo data, pathological
latency on HDDs can let us use that delay to get other work
done.

21 months agolei_mirror+fetch: don't slurp `git show-ref' output
Eric Wong [Wed, 25 Oct 2023 06:33:55 +0000 (06:33 +0000)] 
lei_mirror+fetch: don't slurp `git show-ref' output

While uncommon, some git repos have hundreds of thousands of
refs and slurping that output into memory can bloat the heap.
Introduce a sha_all sub in PublicInbox::SHA to loop until EOF
and rely on autodie for checking sysread errors.

21 months agocindex: use sysread for generating fingerprint
Eric Wong [Wed, 25 Oct 2023 00:29:49 +0000 (00:29 +0000)] 
cindex: use sysread for generating fingerprint

We use sysseek for this file handle elsewhere (since it's passed
to `git rev-list --stdin' multiple times), and sysread ensures
we can use a larger read buffer than the tiny 8K BUFSIZ Perl +
glibc is contrained to.

This also ensures we autodie on sysread failures, since the
autodie import for `read' was missing and we don't call `read'
anywhere else in this file.

21 months agocindex: use run_await wrapper for git commands
Eric Wong [Wed, 25 Oct 2023 00:29:48 +0000 (00:29 +0000)] 
cindex: use run_await wrapper for git commands

Instead of keeping track of live processes ourselves in a hash
table, we'll rely on OnDestroy here to notify us of git command
completions.

21 months agocindex: drop XH_PID global
Eric Wong [Wed, 25 Oct 2023 00:29:47 +0000 (00:29 +0000)] 
cindex: drop XH_PID global

We only the PID locally to call awaitpid.

21 months agocindex: use run_await to read extensions.objectFormat
Eric Wong [Wed, 25 Oct 2023 00:29:46 +0000 (00:29 +0000)] 
cindex: use run_await to read extensions.objectFormat

This saves us the trouble of seeking ourselves by using existing
run_await functionality.  We'll also be more robust to ensure we
only handle the result if the `git config' process exited without
a signal.

21 months agocindex: start using run_await to simplify code
Eric Wong [Wed, 25 Oct 2023 00:29:45 +0000 (00:29 +0000)] 
cindex: start using run_await to simplify code

This saves us some awaitpid calls.  We can also start passing
hashref redirect elements directly to pipe and open perlops,
saving us the trouble of naming some variables.

21 months agocindex: use timer for inits
Eric Wong [Wed, 25 Oct 2023 00:29:44 +0000 (00:29 +0000)] 
cindex: use timer for inits

We'll need to be in the event loop to use run_await in parallel,
so we can't start processes outside of it.  This change isn't
ideal, but it likely keeps the rest of our (hotter) code simpler.

21 months agocindex: avoid awaitpid for popen
Eric Wong [Wed, 25 Oct 2023 00:29:43 +0000 (00:29 +0000)] 
cindex: avoid awaitpid for popen

We can use popen_rd to pass command and callbacks to a
callback sub.  This is another step which may allow us
to get rid of the wantarray forms of popen_rd/popen_wr
in the future.

21 months agocidx_log_p: don't bother with F_SETPIPE_SZ
Eric Wong [Wed, 25 Oct 2023 00:29:42 +0000 (00:29 +0000)] 
cidx_log_p: don't bother with F_SETPIPE_SZ

It doesn't help here since the bottleneck is Xapian indexing
(and not `git log -p').  This fcntl call was also in the way
of switching to ProcessIO.

21 months agoqspawn: simplify internal argument passing
Eric Wong [Wed, 25 Oct 2023 00:29:41 +0000 (00:29 +0000)] 
qspawn: simplify internal argument passing

Now that psgi_return is gone, we can further simplify our
internals to support only psgi_qx and psgi_yield.  Internal
argument passing is reduced and we keep the command env and
redirects in the Qspawn object for as long as it's alive.

I wanted to get rid of finalize() entirely, but it seems
trickier to do when having to support generic PSGI.

21 months agoqspawn: use WwwStatic for fallbacks and error code
Eric Wong [Wed, 25 Oct 2023 00:29:40 +0000 (00:29 +0000)] 
qspawn: use WwwStatic for fallbacks and error code

This ensures we set directives to disable caching since
errors are always transient.

21 months agodrop psgi_return, httpd/async and GetlineBody
Eric Wong [Wed, 25 Oct 2023 00:29:39 +0000 (00:29 +0000)] 
drop psgi_return, httpd/async and GetlineBody

Now that psgi_yield is used everywhere, the more complex
psgi_return and it's helper bits can be removed.  We'll also fix
some outdated comments now that everything on psgi_return has
switched to psgi_yield.  GetlineResponse replaces GetlineBody
and does a better job of isolating generic PSGI-only code.

21 months agowww_coderepo: use psgi_yield
Eric Wong [Wed, 25 Oct 2023 00:29:38 +0000 (00:29 +0000)] 
www_coderepo: use psgi_yield

Yet another drop-in replacement for psgi_return.

21 months agocgit: switch to psgi_yield
Eric Wong [Wed, 25 Oct 2023 00:29:37 +0000 (00:29 +0000)] 
cgit: switch to psgi_yield

Another drop-in replacement using an alternate limiter.

21 months agowww_altid: switch to psgi_yield
Eric Wong [Wed, 25 Oct 2023 00:29:36 +0000 (00:29 +0000)] 
www_altid: switch to psgi_yield

Another drop-in replacement for psgi_return, this one notably
utilizing an unconditional qspawn.filter for gzip unlike the
others.

21 months agoviewvcs: psgi_yield
Eric Wong [Wed, 25 Oct 2023 00:29:35 +0000 (00:29 +0000)] 
viewvcs: psgi_yield

Another drop-in replacement, though I took the opportunity
to avoid unnecessarily bumping the refcount of $ctx->{env}

21 months agorepo_snapshot: psgi_yield
Eric Wong [Wed, 25 Oct 2023 00:29:34 +0000 (00:29 +0000)] 
repo_snapshot: psgi_yield

Another drop-in replacement for psgi_return.

21 months agorepo_atom: switch to psgi_yield
Eric Wong [Wed, 25 Oct 2023 00:29:33 +0000 (00:29 +0000)] 
repo_atom: switch to psgi_yield

To my pleasant surprise, it appears I've managed to make
psgi_yield a drop-in replacement for psgi_return...

21 months agoqspawn: introduce new psgi_yield API
Eric Wong [Wed, 25 Oct 2023 00:29:32 +0000 (00:29 +0000)] 
qspawn: introduce new psgi_yield API

This is intended to replace psgi_return and HTTPD/Async
entirely, hopefully making our code less convoluted while
maintaining the ability to handle slow clients on
memory-constrained systems

This was made possible by the philosophy shift in commit 21a539a2df0c
(httpd/async: switch to buffering-as-fast-as-possible, 2019-06-28).

We'll still support generic PSGI via the `pull' model with a
GetlineResponse class which is similar to the old GetlineBody.

21 months agoxt/check-run: call DS->Reset after all tests
Eric Wong [Wed, 25 Oct 2023 00:29:31 +0000 (00:29 +0000)] 
xt/check-run: call DS->Reset after all tests

This ensures reused processes get a clean start and
avoids surprises as we develop more code around the
DS event loop.

21 months agohttpd/async: require IO arg
Eric Wong [Wed, 25 Oct 2023 00:29:30 +0000 (00:29 +0000)] 
httpd/async: require IO arg

Callers that want to requeue can call PublicInbox::DS::requeue
directly and not go through the convoluted argument handling
via PublicInbox::HTTPD::Async->new.

21 months agoqspawn: drop unused err arg for ->event_step
Eric Wong [Wed, 25 Oct 2023 00:29:29 +0000 (00:29 +0000)] 
qspawn: drop unused err arg for ->event_step

It's no longer needed since psgi_qx doesn't use a pipe, anymore.

21 months agoqspawn: psgi_return allows list for callback args
Eric Wong [Wed, 25 Oct 2023 00:29:28 +0000 (00:29 +0000)] 
qspawn: psgi_return allows list for callback args

This slightly simplifies our GitHTTPBackend wrapper.
We can also use shorter variable names to avoid wrapping some
lines.

21 months agowww_coderepo: capture uses a flattened list
Eric Wong [Wed, 25 Oct 2023 00:29:27 +0000 (00:29 +0000)] 
www_coderepo: capture uses a flattened list

We no longer need a multi-dimensional list to pass multiple
arguments to the psgi_qx callback.  This simplifies usage
and reduces allocations.

21 months agopsgi_qx: use a temporary file rather than pipe
Eric Wong [Wed, 25 Oct 2023 00:29:26 +0000 (00:29 +0000)] 
psgi_qx: use a temporary file rather than pipe

A pipe requires more context switches, syscalls, and code to
deal with unpredictable pipe EOF vs waitpid ordering.  So just
use the new spawn/aspawn features to automatically handle
slurping output into a string.

21 months agospawn: support synchronous run_qx
Eric Wong [Wed, 25 Oct 2023 00:29:25 +0000 (00:29 +0000)] 
spawn: support synchronous run_qx

This is similar to `backtick` but supports all our existing spawn
functionality (chdir, env, rlimit, redirects, etc.).  It also
supports SCALAR ref redirects like run_script in our test suite
for std{in,out,err}.

We can probably use :utf8 by default for these redirects, even.

21 months agolimiter: split out from qspawn
Eric Wong [Wed, 25 Oct 2023 00:29:24 +0000 (00:29 +0000)] 
limiter: split out from qspawn

It's slightly better organized this way, especially since
`publicinboxLimiter' has its own user-facing config section
and knobs.  I may use it in LeiMirror and CodeSearchIdx for
process management.

21 months agocindex: basic inboxes are non-fatal for --associate
Eric Wong [Tue, 24 Oct 2023 11:44:29 +0000 (11:44 +0000)] 
cindex: basic inboxes are non-fatal for --associate

We need to gracefully continue when a user tries to associate
with --all but has basic (or completely unindexed) inboxes.

21 months agot/cindex: use autodie
Eric Wong [Tue, 24 Oct 2023 11:44:28 +0000 (11:44 +0000)] 
t/cindex: use autodie

More tests to come, so cut down on the noise in the test code.

21 months agocindex: --associate fails when no inboxes are given
Eric Wong [Tue, 24 Oct 2023 11:44:27 +0000 (11:44 +0000)] 
cindex: --associate fails when no inboxes are given

This functionality still needs to be fleshed out, but we
definitely can't associate coderepos to inboxes if we don't have
any inboxes as candidates.

21 months agoxap_helper.pm: quiet undefined warnings at shutdown
Eric Wong [Mon, 23 Oct 2023 19:35:17 +0000 (19:35 +0000)] 
xap_helper.pm: quiet undefined warnings at shutdown

We can't force EBADF with high-level I/O wrappers like we can
in C, so instead we quiet Perl itself.

21 months agot/init.t: don't modify $HOME/.public-inbox/config in test
Eric Wong [Mon, 23 Oct 2023 08:58:12 +0000 (08:58 +0000)] 
t/init.t: don't modify $HOME/.public-inbox/config in test

Oops :x

21 months agowww: fully qualify read_all subroutine call
Eric Wong [Mon, 23 Oct 2023 08:24:20 +0000 (08:24 +0000)] 
www: fully qualify read_all subroutine call

IMHO, this is not worth importing here since it's only called at
startup.

Fixes: 19b791f4894e (use read_all in more places to improve safety)
21 months agolei: simplify startq/au_done wakeup notifications
Eric Wong [Thu, 19 Oct 2023 01:14:31 +0000 (01:14 +0000)] 
lei: simplify startq/au_done wakeup notifications

We only need to write one byte at MUA start instead of a byte
for every LeiXSearch worker.  Also, make sure it succeeds by
enabling autodie for syswrite.

When reading, we can rely on `:perlio' layer `read' semantics
to retry on EINTR to avoid looping and other error checking.

21 months agoRevert "kqnotify: drop EV_CLEAR (edge triggering)"
Eric Wong [Wed, 18 Oct 2023 20:56:08 +0000 (20:56 +0000)] 
Revert "kqnotify: drop EV_CLEAR (edge triggering)"

This reverts commit 13a2088c74fdb4fa51cd97cefc00862cc2082330.

It's causing errors on an OpenBSD development snapshot while
despite being fine on OpenBSD 7.3 (amd64) and other *BSDs I've
tested.

Reported-by: Štěpán Němec <stepnem@smrk.net>
Link: https://public-inbox.org/meta/20231018170111+0200.599564-stepnem@smrk.net/
21 months agoidx_stack: use autodie + read_all
Eric Wong [Tue, 17 Oct 2023 23:38:15 +0000 (23:38 +0000)] 
idx_stack: use autodie + read_all

We'll also add a note to support multi-hash git repos once git
itself gains that ability.

21 months agoconvert: use read_all to simplify error checks
Eric Wong [Tue, 17 Oct 2023 23:38:14 +0000 (23:38 +0000)] 
convert: use read_all to simplify error checks

There wasn't a need to loop anyways with Perl `read' since
the default PerlIO layer will retry.

21 months agolei_config: drop redundant open check
Eric Wong [Tue, 17 Oct 2023 23:38:13 +0000 (23:38 +0000)] 
lei_config: drop redundant open check

autodie already takes care of checking for open failures.

21 months agolei_auth: update comments and use v5.12
Eric Wong [Tue, 17 Oct 2023 23:38:12 +0000 (23:38 +0000)] 
lei_auth: update comments and use v5.12

There's nothing affected by the `unicode_strings' feature, so
it's safe to use v5.12, here.

21 months agolei: use autodie where appropriate
Eric Wong [Tue, 17 Oct 2023 23:38:11 +0000 (23:38 +0000)] 
lei: use autodie where appropriate

This makes us a bit harsher with misbehaving clients, but we
only have one client implementation at the moment.

21 months agoxt/mem-imapd-tls: reduce FDs for lsof use
Eric Wong [Tue, 17 Oct 2023 23:38:10 +0000 (23:38 +0000)] 
xt/mem-imapd-tls: reduce FDs for lsof use

We need some pipes in our parent process to capture the output
of lsof(1), so give us some more padding for temporary FDs.

21 months agoxt/mem-imapd-tls: remove unused/broken epoll imports
Eric Wong [Tue, 17 Oct 2023 23:38:09 +0000 (23:38 +0000)] 
xt/mem-imapd-tls: remove unused/broken epoll imports

The `:epoll' tag has been gone for a few weeks, and EPOLLIN
isn't used in this file anywhere.

Fixes: 3005c1bc5d05 (ds: use object-oriented API for epoll)
21 months agoinit: use autodie to reduce distractions
Eric Wong [Tue, 17 Oct 2023 23:38:08 +0000 (23:38 +0000)] 
init: use autodie to reduce distractions

This hurts startup time a bit, but our tests use run_script
by default and I don't think normal users call -init enough
to care.

21 months agoinit: drop extraneous `+'
Eric Wong [Tue, 17 Oct 2023 23:38:07 +0000 (23:38 +0000)] 
init: drop extraneous `+'

It's actually valid Perl syntax, but still confusing to look at.

Fixes: add90b9504f4 ("support -C (chdir) for most non-daemon commands")
21 months agotest_common: use $cwdfh for every run_script command
Eric Wong [Tue, 17 Oct 2023 23:38:06 +0000 (23:38 +0000)] 
test_common: use $cwdfh for every run_script command

It's not lei-specific since we have `-C' to perform chdir
for multiple admin commands.

21 months agotest_common: only hide TCP port in messages
Eric Wong [Tue, 17 Oct 2023 23:38:05 +0000 (23:38 +0000)] 
test_common: only hide TCP port in messages

v2:// lei outputs are on the filesystem, so putting $HOST:$PORT
is nonsensical.  We'll also keep `127.0.0.1' or `[::1]' since
it's harmless and can point out obvious errors in system
configuration when testing with old Perls or libraries.

21 months agotest_common: use autodie and read_all where possible
Eric Wong [Tue, 17 Oct 2023 23:38:04 +0000 (23:38 +0000)] 
test_common: use autodie and read_all where possible

Noise reduction to help my aging eyes.

21 months agot/lei-up: additional diagnostics for match failures
Eric Wong [Tue, 17 Oct 2023 23:38:03 +0000 (23:38 +0000)] 
t/lei-up: additional diagnostics for match failures

I'm not sure why, but this test just failed for some odd reason
from `make check-run' on my Debian bullseye workstatation.

21 months agosyscall: common $F_SETPIPE_SZ definition
Eric Wong [Tue, 17 Oct 2023 23:38:02 +0000 (23:38 +0000)] 
syscall: common $F_SETPIPE_SZ definition

We use this in various places to minimize or maximize pipe
size on Linux.  So keep it all in one place.

21 months agocindex: drop some unused functions
Eric Wong [Tue, 17 Oct 2023 23:38:01 +0000 (23:38 +0000)] 
cindex: drop some unused functions

They're no longer needed with the way PublicInbox::CidxLogP is
currently implemented.

21 months agods: get rid of SetLoopTimeout
Eric Wong [Tue, 17 Oct 2023 23:38:00 +0000 (23:38 +0000)] 
ds: get rid of SetLoopTimeout

It's not worth the code and memory to have a setter method we
never use outside of tests.

21 months agods: introduce and use do_fork helper
Eric Wong [Tue, 17 Oct 2023 23:37:59 +0000 (23:37 +0000)] 
ds: introduce and use do_fork helper

This ensures we handle RNG reseeding and resetting the event
loop properly in child processes after forking.