]> git.ipfire.org Git - thirdparty/public-inbox.git/log
thirdparty/public-inbox.git
19 months agoxap_helper.h: fix non-assignable stderr case
Eric Wong [Fri, 1 Dec 2023 02:07:03 +0000 (02:07 +0000)] 
xap_helper.h: fix non-assignable stderr case

I mixed up "flush" with "close" :x

Fixes: 87b7f633f241 (xap_helper: implement mset endpoint for WWW, IMAP, etc...)
19 months agot/xap_helper: make sendmsg errors more obvious
Eric Wong [Fri, 1 Dec 2023 02:07:02 +0000 (02:07 +0000)] 
t/xap_helper: make sendmsg errors more obvious

By ignoring SIGPIPE, we hit our own error path and emit an informative
error message instead of dying abruptly and requiring somebody to run
`echo $?' to see the child status from their shell.

19 months agodoc: config: fix grammar for nameIsUrl
Eric Wong [Fri, 1 Dec 2023 02:01:20 +0000 (02:01 +0000)] 
doc: config: fix grammar for nameIsUrl

Kyle Meyer <kyle@kyleam.com> wrote:
> Eric Wong writes:
> > +Treat the name of the public inbox as it's unqualified URL when
>
> s/it's/its/

Thanks, will push this fix out:

-------8<------
Subject: [PATCH] doc: config: fix grammar for nameIsUrl

Reported-by: Kyle Meyer <kyle@kyleam.com>
Link: https://public-inbox.org/meta/87bkbazp5g.fsf@kyleam.com/
19 months agocodesearch: use retry_reopen for WWW
Eric Wong [Thu, 30 Nov 2023 21:40:47 +0000 (21:40 +0000)] 
codesearch: use retry_reopen for WWW

As with mail search, a cindex may be updated while WWW is
serving requests.  Thus we must reopen the Xapian DB when
the revision we're using becomes stale.

19 months agoinbox: shrink data structures for publicinbox.*.hide
Eric Wong [Thu, 30 Nov 2023 11:41:07 +0000 (11:41 +0000)] 
inbox: shrink data structures for publicinbox.*.hide

We no longer vivify the intermediate $ibx->{-hide} hashref,
instead we use $ibx->{-hide_$KEY} directly.  This avoids
an intermediate hashref and extra hash table lookups.

19 months agowww_listing: support publicInbox.nameIsUrl
Eric Wong [Thu, 30 Nov 2023 11:41:06 +0000 (11:41 +0000)] 
www_listing: support publicInbox.nameIsUrl

This is a convenient (and slightly memory-saving) alternative to
specifying a `publicinbox.*.url' entry for every single inbox
when using publicinbox.wwwListing.

19 months agogit_async_cat: use git from "all" extindex if possible
Eric Wong [Thu, 30 Nov 2023 11:41:05 +0000 (11:41 +0000)] 
git_async_cat: use git from "all" extindex if possible

For inboxes associated with an extindex (currently only the
special "all") one, we can share the git process across
all those inboxes unambiguously when retrieving full SHA-1
blobs.

The comment for my proposed patch is also out-of-date as that
git speedup has been a part of git since 2.33.

19 months agoinbox: expire resources more aggressively
Eric Wong [Thu, 30 Nov 2023 11:41:04 +0000 (11:41 +0000)] 
inbox: expire resources more aggressively

We no longer trigger git cleanups from the Inbox package since
`git cat-file' users have their own cleanup to support git
coderepos not associated with any inbox.

This change means we unconditionally expire SQLite and Xapian
FDs and some internal caches regardless of git activity.  The
old logic was irrelevant to Gcf2 (libgit2) users anyways since
we couldn't determine whether or not an inbox was active based
on {inflight} git requests, and upcoming changes will make it
inaccurate for all extindex/cindex users as well.

Opening SQLite and Xapian DBs is fairly cheap; so it's a small
price to pay to reduce memory use and fragmentation.

19 months agocindex: speed up initial scan setup phase
Eric Wong [Thu, 30 Nov 2023 11:41:03 +0000 (11:41 +0000)] 
cindex: speed up initial scan setup phase

This brings a no-op -cindex scan of a git.kernel.org mirror
down from 70s to 10s with a hot cache on a busy machine.

CPU-intensive SHA-256 fingerprinting of the `git show-ref'
result can be parallelized on shard workers.  Future changes can
move more of the initial scan setup phase into shard workers for
more parallelism.

But most of the performance for skipping unchanged repos is
gained from delaying the commit time reading until we've seen
the fingerprint is out-of-date, since reading commit times
requires a large amount of I/O compared to only reading refs
for fingerprints.

19 months agospawn: drop IO layer support from redirects
Eric Wong [Thu, 30 Nov 2023 11:41:02 +0000 (11:41 +0000)] 
spawn: drop IO layer support from redirects

When setting up stdin for commands, the write_file API is
convenient enough nowadays to not be worth having special
support with process spawning.

When reading stdout of commands, we should probably be using
utf8_maybe everywhere since there'll always be legacy encodings
in git repos.

Reading regular files with :utf8 also results in worse memory
management since the file size cannot be used as a hint.

19 months agocindex: skip getpid guard for most OnDestroy use
Eric Wong [Thu, 30 Nov 2023 11:41:01 +0000 (11:41 +0000)] 
cindex: skip getpid guard for most OnDestroy use

We no longer fork after cidx_init, so there's no need to spend
CPU cycles on the getpid() syscall, especially since it's no
longer cached on glibc while syscalls are also more expensive
these days due to CPU vulnerability mitigations.

19 months agogit: share unlinked pack checking code with gcf2
Eric Wong [Thu, 30 Nov 2023 11:41:00 +0000 (11:41 +0000)] 
git: share unlinked pack checking code with gcf2

It saves some code in case we keep libgit2 around.

19 months agocindex: store extensions.objectFormat with repo data
Eric Wong [Thu, 30 Nov 2023 11:40:59 +0000 (11:40 +0000)] 
cindex: store extensions.objectFormat with repo data

This will allow WWW to use a combined LeiALE-like
thing to reduce git processes.

19 months agocindex: keep batch pipe for pruning SHA-256 repos
Eric Wong [Thu, 30 Nov 2023 11:40:58 +0000 (11:40 +0000)] 
cindex: keep batch pipe for pruning SHA-256 repos

This fixes the case where we're running both SHA-256 and SHA-1.
There's no tests for SHA-256, yet, but the bug is pretty obvious
upon reading the code.

19 months agocindex: only create {-cidx_err} field on failures
Eric Wong [Thu, 30 Nov 2023 11:40:57 +0000 (11:40 +0000)] 
cindex: only create {-cidx_err} field on failures

We only use it as a boolean flag, and there's no need to waste
space for common, non-error cases.

19 months agoconfig: reject newlines consistently in dir names
Eric Wong [Thu, 30 Nov 2023 11:40:56 +0000 (11:40 +0000)] 
config: reject newlines consistently in dir names

Explicitly drop support for "\n" in git coderepo pathnames as
we do other stuff.  Gcf2 (our libgit2 helper) was always
broken with "\n" in pathnames, and I'm not sure if cgit config
files work with them, either.  Dealing with newline characters
requires extra complexity that I'm not willing to deal with when
managing alternates files.

19 months agocodesearch: allow inbox count to exceed matches
Eric Wong [Thu, 30 Nov 2023 11:40:55 +0000 (11:40 +0000)] 
codesearch: allow inbox count to exceed matches

It's entirely possible for public inboxes to have zero patches
in them, so the amount of match slots may not match match the
number of joined ekeys.

19 months agocindex: fix store_repo+repo_stored on no-op
Eric Wong [Thu, 30 Nov 2023 11:40:54 +0000 (11:40 +0000)] 
cindex: fix store_repo+repo_stored on no-op

It's possible to update the fingerprint for a given repo when we
have no commits to index on because they were already done for
another repo.  Thus we'll always vivify $repo_ctx->{active}
before calling store_repo since $active may've been undef.

19 months agodoc: fix a few typos and wording issues
Štěpán Němec [Wed, 29 Nov 2023 12:02:52 +0000 (13:02 +0100)] 
doc: fix a few typos and wording issues

19 months agodoc: -cindex: correct and unify -g GIT_DIR usage string and man page
Štěpán Němec [Wed, 29 Nov 2023 12:02:51 +0000 (13:02 +0100)] 
doc: -cindex: correct and unify -g GIT_DIR usage string and man page

Fixes: c76a20d75200 ("cindex: require `-g GIT_DIR' or `-r PROJECT_ROOT'")
19 months agowww: mail_diff: add missing </pre> tag
Eric Wong [Tue, 28 Nov 2023 17:37:01 +0000 (17:37 +0000)] 
www: mail_diff: add missing </pre> tag

Found by tidy(1) while dealing with other stuff.

19 months agowww: mail_diff: add final newline before diffing
Eric Wong [Tue, 28 Nov 2023 17:37:00 +0000 (17:37 +0000)] 
www: mail_diff: add final newline before diffing

This gets rid of the "\ No newline at end of file"
since it's distracting noise.

19 months agowww: mail_diff: fix optional address obfuscation
Eric Wong [Tue, 28 Nov 2023 17:36:59 +0000 (17:36 +0000)] 
www: mail_diff: fix optional address obfuscation

We need to load the proper package and fully-qualify the sub
call since we shouldn't load Hval in lei.  Some users use this
feature even if its broken, oh well :<

19 months agolei q: fix --no-import-before completion + docs
Eric Wong [Tue, 28 Nov 2023 17:36:58 +0000 (17:36 +0000)] 
lei q: fix --no-import-before completion + docs

--no-import-before skips importing entire messages, not just
keywords, so it can cause permanent data loss if -o is pointed
to precious data.

19 months agowww: load cindex join data for ->ALL, too
Eric Wong [Tue, 28 Nov 2023 17:55:09 +0000 (17:55 +0000)] 
www: load cindex join data for ->ALL, too

This ensures the /all/ extindex can have auto-associations
with coderepos just like normal inboxes do.

19 months agowww: start working on a repo listing
Eric Wong [Tue, 28 Nov 2023 14:56:27 +0000 (14:56 +0000)] 
www: start working on a repo listing

The HTML is still extremely rough, but links seem to be mostly
working...

19 months agocindex: extra quit checks
Eric Wong [Tue, 28 Nov 2023 14:56:26 +0000 (14:56 +0000)] 
cindex: extra quit checks

We don't want to be accessing uninitialized variables on
process teardown since much of our control flow revolves
around DESTROY for dependency handling.

19 months agoadmin: resolve_git_dir respects symlinks
Eric Wong [Tue, 28 Nov 2023 14:56:25 +0000 (14:56 +0000)] 
admin: resolve_git_dir respects symlinks

Absolute pathnames of git coderepos are stored in the cindex,
but we should favor paths relative to $ENV{PWD} since it
respects symlinks in the heirarchy.

Respecting symlinks makes it easier to migrate cindex to
new storage as old storage wears out and to relocate the
storage device onto another machine.

19 months agogit: speed up Git->new by 5% or so
Eric Wong [Tue, 28 Nov 2023 14:56:24 +0000 (14:56 +0000)] 
git: speed up Git->new by 5% or so

This becomes noticeable when loading lots of coderepos on
my local mirror of git.kernel.org now that we can load repos
from cindex.

19 months agocindex: require `-g GIT_DIR' or `-r PROJECT_ROOT'
Eric Wong [Tue, 28 Nov 2023 14:56:23 +0000 (14:56 +0000)] 
cindex: require `-g GIT_DIR' or `-r PROJECT_ROOT'

Accepting @ARGV without switches ends up being ambiguous with
optional parameters for --join and --show.  Requiring users to
specify `--join=' or `--show=' is a bit awkward (as it with
-clone --objstore= and the like, but that is historical baggage
we need to carry at this point...)

19 months agogit: speed up ->git_path for non-worktrees
Eric Wong [Tue, 28 Nov 2023 14:56:22 +0000 (14:56 +0000)] 
git: speed up ->git_path for non-worktrees

Only worktrees need to use `git rev-parse --git-path', so avoid
the spawn overhead of a new process.  With the SolverGit.pm
limit on coderepo scans disabled and scanning over 800 git repos
for git@vger matches, this reduces up xt/solver.t times by
roughly 25%.

19 months agowww: load and use cindex join data
Eric Wong [Tue, 28 Nov 2023 14:56:21 +0000 (14:56 +0000)] 
www: load and use cindex join data

This is a major step in solving the problem of having to
manually associate hundreds/thousands of coderepos with
hundreds/thousands of public-inboxes to power solver
(and more).

19 months agohval: use File::Spec to make relative paths for href
Eric Wong [Tue, 28 Nov 2023 14:56:20 +0000 (14:56 +0000)] 
hval: use File::Spec to make relative paths for href

File::Spec->abs2rel doesn't touch the filesystem at all when
given an absolute base arg ($env->{PATH_INFO}), so we can rely
on it to generate relative links that work with the `mount'
from Plack::Builder and also people running `wget -r' mirrors.

19 months agoxap_helper: implement mset endpoint for WWW, IMAP, etc...
Eric Wong [Tue, 28 Nov 2023 14:56:19 +0000 (14:56 +0000)] 
xap_helper: implement mset endpoint for WWW, IMAP, etc...

The C++ version will allow us to take full advantage of Xapian's
APIs for better queries, and the Perl bindings version can still
be advantageous in the future since we'll be able to support
timeouts effectively.

19 months agoxap_helper.h: move cindex endpoints to separate file
Eric Wong [Tue, 28 Nov 2023 14:56:18 +0000 (14:56 +0000)] 
xap_helper.h: move cindex endpoints to separate file

It ought to help a bit with organization since xap_helper.h
is getting somewhat large and we'll need new endpoints to
support WWW, lei, and whatever else that needs to come.

19 months agosolver: schedule cleanup after synchronous git->check
Eric Wong [Tue, 28 Nov 2023 14:56:17 +0000 (14:56 +0000)] 
solver: schedule cleanup after synchronous git->check

We don't want hundreds of git cat-file processes for coderepos
lingering around.

19 months agocodesearch: eliminate redundant substitutions
Eric Wong [Tue, 28 Nov 2023 14:56:16 +0000 (14:56 +0000)] 
codesearch: eliminate redundant substitutions

We store the full path name and xap_terms already removes
the `P' character, so the loop and substr calls are a
no-op replacing `/' with `/'.

19 months agot/cindex*: require SCM_RIGHTS for these tests
Eric Wong [Tue, 28 Nov 2023 14:56:15 +0000 (14:56 +0000)] 
t/cindex*: require SCM_RIGHTS for these tests

Code search will require SCM_RIGHTS, and Inline::C on BSDs
probably isn't too onerous a dependency for new features as
all the ones I've tested have it packaged.

Furthermore, requiring SCM_RIGHTS isn't far off since OpenBSD's
Perl is patched to route the `syscall' perlop through libc[1],
while NetBSD[2] and FreeBSD[3] actually do strive for backwards
compatibility.  We'd just need to use the numbers and not rely
on syscall.ph shipped with Perl since the macro names themselves
are unstable.

[1] https://cvsweb.openbsd.org/src/gnu/usr.bin/perl/gen_syscall_emulator.pl
[2] https://www.netbsd.org/docs/internals/en/chap-processes.html#syscall_versioning
[3] https://wiki.freebsd.org/AddingSyscalls#Backward_compatibily

19 months agotest_common: create_*: detect changes all parameters
Eric Wong [Tue, 28 Nov 2023 14:56:14 +0000 (14:56 +0000)] 
test_common: create_*: detect changes all parameters

Data::Dumper+B::Deparse seems fast enough to generate cache keys
with, so this makes updating and developing tests easier (as
opposed to forcing the developer to change the identifier).  The
main downside is we'll have to deal with cache expiration, but
"make clean" seems overly aggressive already (it keeps blowing
away the clones made by t/cindex-join.t :<)

19 months agodisallow NUL characters in Message-ID and List-Id
Eric Wong [Mon, 27 Nov 2023 22:20:59 +0000 (22:20 +0000)] 
disallow NUL characters in Message-ID and List-Id

While MTAs seem to stop '\0' from appearing in headers, users
fetching archives via git remain susceptible to having '\0' land
in archives.  So we'll filter them out of Xapian and SQLite DBs
to avoid interopability problems with CLI tools since there's no
known messages in lore or any of my archives which feature them.

Avoiding '\0' will ensure all indexed Message-IDs and List-Ids
can be specified from the command-line (although some characters
will still require $(printf) contortions).

As with Message-ID, List-Id fields with /\n\t\r/ characters will
also be stripped for indexing.  I will assume whatever went wrong
with the References: header in
<https://public-inbox.org/git/656C30A1EFC89F6B2082D9B6@localhost/raw>
could also happen to the List-Id header.

This is inspired by commit aca47e05a6026c12c768753c87e6ff769ef6bee4
(Import: Don't copy nulls from emails into git, 2018-07-07)

19 months agowww: qs_html: fix escaping of `q' param
Eric Wong [Mon, 27 Nov 2023 10:23:48 +0000 (10:23 +0000)] 
www: qs_html: fix escaping of `q' param

Our use of MID_ESC characters was only intended for the pathname
component of URIs and not appropriate for the query string
component.  So use a different $unsafe parameter list for
uri_escape to make the result appropriate for query strings by
disallowing [\&\'\+=] characters.  Most notably, this change
also allows us to accept `/' (slash) unescaped to make dfn: queries
nicer to look at.

Finally, we'll also add a ascii_html call on the URI-escaped
result as an extra safety measure even though it's not really
needed.

As far as I can tell, the code without this fix didn't result in
in an HTML injection since all our uses of uri_escape did escape
angle brackets.

Reported-by: Ricardo Cañuelo <ricardo.canuelo@collabora.com>
Link: https://public-inbox.org/meta/87o7ff4nlk.fsf@collabora.com/
Tested-by: Ricardo Cañuelo <ricardo.canuelo@collabora.com>
19 months agot/nntpd-tls: avoid test failure on OpenBSD 7.3
Eric Wong [Mon, 27 Nov 2023 07:26:28 +0000 (07:26 +0000)] 
t/nntpd-tls: avoid test failure on OpenBSD 7.3

The LibreSSL 3.7.2 on my OpenBSD 7.3 VM seems return 7 bytes of
junk data before EOF/ECONNRESET when a client attempts to write
plain-text to a TLS socket.

Tested-by: Štěpán Němec <stepnem@smrk.net>
20 months agoxap_helper.h: avoid some off_t vs size_t problems
Eric Wong [Mon, 27 Nov 2023 04:05:47 +0000 (04:05 +0000)] 
xap_helper.h: avoid some off_t vs size_t problems

We'll introduce a helper to cast off_t to size_t consistently
for mmap/munmap/calloc calls which require size_t.  Also, an
extra check for multiplication overflow can be helpful just
in case we end up with a gigantic file roots file.

20 months agoxap_helper: avoid strerror(3) inside signal handler
Eric Wong [Sun, 26 Nov 2023 20:07:45 +0000 (20:07 +0000)] 
xap_helper: avoid strerror(3) inside signal handler

It's not async-signal-safe and the glibc implementation uses
malloc via asnprintf.  Practically it's not a problem unless the
kernel OOMs and the write(2) fails to the self-pipe.

20 months agodrop redundant calls to DS->Reset
Eric Wong [Sun, 26 Nov 2023 21:08:01 +0000 (21:08 +0000)] 
drop redundant calls to DS->Reset

Reset gets called on END{} anyways to workaround DBI lifetime
problems, so there's no need to call it near exit.  We can't
replace calls to POSIX::_exit with `exit' to force END{} to
run just yet, as there are still some lingering destruction
ordering problems on newer DBI and or Perls.

20 months agogit: improve coupling with {sock} and {inflight} fields
Eric Wong [Sun, 26 Nov 2023 02:11:04 +0000 (02:11 +0000)] 
git: improve coupling with {sock} and {inflight} fields

While the {inflight} array should be tied to the IO object even
more tightly, that's not an easy task with our current code.  So
take some small steps by introducing a gcf_inflight helper to
validate the ownership of the process and to drain the inflight
array via the awaitpid callback.

This hopefully fix problems with t/lei-q-save.t (still) hanging
occasionally on v2 outputs since git->cleanup/->DESTROY was getting
called in v2 shard workers.

20 months agogit: move rbuf handling to PublicInbox::IO
Eric Wong [Sun, 26 Nov 2023 02:11:03 +0000 (02:11 +0000)] 
git: move rbuf handling to PublicInbox::IO

The long-term plan is to share non-blocking read buffering logic
with HTTP/NNTP/IMAP/POP3 and also XapClient.

20 months agoxap_helper: allow PI_NO_CXX to disable C++ in more places
Eric Wong [Sun, 26 Nov 2023 02:11:02 +0000 (02:11 +0000)] 
xap_helper: allow PI_NO_CXX to disable C++ in more places

This also reduces repetition in the setup code.

20 months agoxap_client: pass arguments to top-level xap_helper
Eric Wong [Sun, 26 Nov 2023 02:11:01 +0000 (02:11 +0000)] 
xap_client: pass arguments to top-level xap_helper

This ensures our tests actually test the -j0 and -j1 cases
properly.

20 months agoxap_client: attach PID to the IO object
Eric Wong [Sun, 26 Nov 2023 02:11:00 +0000 (02:11 +0000)] 
xap_client: attach PID to the IO object

As with our popen_* uses, we can simplify callers by using
attach_pid to handle automatic reaping upon close.

20 months agoxap_helper_cxx: do not copy xap_helper.h source
Eric Wong [Sun, 26 Nov 2023 02:10:59 +0000 (02:10 +0000)] 
xap_helper_cxx: do not copy xap_helper.h source

No need to waste memory bandwidth when we can just rely on
the preprocessor to load the header.

20 months agods: long_step: eliminate redundant fileno call
Eric Wong [Sat, 25 Nov 2023 20:54:35 +0000 (20:54 +0000)] 
ds: long_step: eliminate redundant fileno call

We already stash the associated FD for reporting at startup and
don't need to call `fileno' again.  Found via manual code
inspection while considering the effort to make async {forward}
from PublicInbox::HTTP more like the generic long_response API
and {long_cb} field used by IMAP/NNTP/POP3.

20 months agoselect+poll: have caller retry on EINTR
Eric Wong [Sat, 25 Nov 2023 20:54:34 +0000 (20:54 +0000)] 
select+poll: have caller retry on EINTR

We can't assume signals are blocked when neither signalfd nor
EVFILT_SIGNAL are in use.  So just return an empty result so
the caller can recalculate the timeout.

I found this bug while making xt/httpd-async-stream.t
use our event loop to reap processes but have abandoned
that effort for now since it didn't save any code.

20 months agohttp: fix pipelining during long async requests
Eric Wong [Sat, 25 Nov 2023 20:54:33 +0000 (20:54 +0000)] 
http: fix pipelining during long async requests

We must not attempt to read request bodies from the HTTP client
while processing a long request since that drains pipelined
requests.  The NNTP/IMAP/POP3 event_step callbacks follow the
same behavior when {long_cb} is present from ->long_response.

This bug has little real-world consequence since HTTP/1.1
pipelining is not widely-used, especially when behind varnish
or other reverse proxies.

I found this bug while randomly strace-ing an active -netd
process to see the kind of traffic it was seeing.

20 months agodoc/extindex: document --dedupe switch
Eric Wong [Sat, 25 Nov 2023 20:25:20 +0000 (20:25 +0000)] 
doc/extindex: document --dedupe switch

We've had it since v1.7.0 when -extindex was introduced,
but it was never documented outside of commit messages.

Reviewed-by: Štěpán Němec <stepnem@smrk.net>
20 months agoexamples/unsubscribe.milter: limit scope of munging
Eric Wong [Sat, 25 Nov 2023 01:52:25 +0000 (01:52 +0000)] 
examples/unsubscribe.milter: limit scope of munging

We don't want the milter to munge List-Unsubscribe headers from
external (incoming) mlmmj lists, only lists hosted on the server
running unsubscribe.milter.

Adding support for an allow_domains file should've been enough,
but this further restricts the milter to only operating on Postfix
connections from localhost.

20 months agot/cindex-join: fix warnings from a missing comma
Eric Wong [Sat, 25 Nov 2023 00:09:03 +0000 (00:09 +0000)] 
t/cindex-join: fix warnings from a missing comma

Yes, that was valid Perl syntax :x

20 months agocindex: fix --join=reset and speed up incremental joins
Eric Wong [Fri, 24 Nov 2023 09:53:46 +0000 (09:53 +0000)] 
cindex: fix --join=reset and speed up incremental joins

`reset' means we want to ignore existing join data, while
the default (non-reset) means we perform an incremental
join while taking into account existing (fuzzy) join data.

20 months agolei_saved_search: don't create Git object during ->DESTROY
Eric Wong [Wed, 22 Nov 2023 21:24:11 +0000 (21:24 +0000)] 
lei_saved_search: don't create Git object during ->DESTROY

This fixes t/lei-q-save.t getting stuck since $self->{ale} is
already gone by the time DESTROY gets called.

20 months agowatch: support `watch=false' to negate watchspam
Eric Wong [Wed, 22 Nov 2023 01:04:18 +0000 (01:04 +0000)] 
watch: support `watch=false' to negate watchspam

For users hosting read-only mirrors (via clone|fetch) and feeding
inboxes via -watch

20 months agolei_to_mail: don't close STDOUT unless it is a mbox* output
Eric Wong [Wed, 22 Nov 2023 00:13:31 +0000 (00:13 +0000)] 
lei_to_mail: don't close STDOUT unless it is a mbox* output

We only care about error checking when stdout is an mbox output
pointed to a pathname.  This is noticeable with `lei up' with
multiple non-mbox* destinations.  We'll also ensure throwing
exceptions to trigger lei->x_it from lei->do_env results in the
epoll/kqueue watch being discarded, otherwise commands may never
terminate (leading to stuck tests)

20 months agocindex: rename --associate to --join, test w/ real repos
Eric Wong [Tue, 21 Nov 2023 12:43:15 +0000 (12:43 +0000)] 
cindex: rename --associate to --join, test w/ real repos

The association data is just stored as deflated JSON in Xapian
metadata keys of shard[0] for now.  It should be reasonably
compact and fit in memory for now since we'll assume sane,
non-malicious git coderepo history, for now.

The new cindex-join.t test requires TEST_REMOTE_JOIN=1 to be
set in the environment and tests the joins against the inboxes
and coderepos of two small projects with a common history.

Internally, we'll use `ibx_off', `root_off' instead of `ibx_id'
and `root_id' since `_id' may be mistaken for columns in an SQL
database which they are not.

20 months agodoc/cindex: point no-fsync,dangerous to -index(1)
Eric Wong [Tue, 21 Nov 2023 12:43:14 +0000 (12:43 +0000)] 
doc/cindex: point no-fsync,dangerous to -index(1)

There's no point in duplicating --no-fsync documentation across
manpages.  --dangerous can be useful for reducing SSD wear, so
add a pointer to it as well.

20 months agocindex: avoid unneeded and redundant `local' calls
Eric Wong [Tue, 21 Nov 2023 12:43:13 +0000 (12:43 +0000)] 
cindex: avoid unneeded and redundant `local' calls

We only set $MAX_SIZE at startup, and there's no need to
use a local $self->{roots} for the per-repo roots array.

20 months agosearchidx: run `git patch-id' in parallel
Eric Wong [Mon, 20 Nov 2023 19:22:32 +0000 (19:22 +0000)] 
searchidx: run `git patch-id' in parallel

Informal benchmarks show a rough 5% indexing improvement on an
SMP system when there are idle cores due to Xapian shards being
I/O bound (since `git patch-id' is mainly CPU bound).

This is only parallelized on a per-patch basis.  Further
increasing parallelism would increase complexity and probably
not be worth it since `git patch-id' is reasonably fast while
our text indexing tends to be slow.

20 months agogit: return upon self->close
Eric Wong [Mon, 20 Nov 2023 08:46:01 +0000 (08:46 +0000)] 
git: return upon self->close

I encountered the odd lack of `return' while chasing Gcf2 bugs
on CentOS 7.x which resulted in commit 7d06b126e939
("gcf2: fix autodie usage for older Perl") and commit e618c7654794
("gcf2client: add alias for PublicInbox::Git::fail") before
realizing the lack of `return' here wasn't the culprit behind
failures on CentOS 7.x.

However, the use of a `return' here appears required in case we
actually hit the error path, since falling through and
attempting my_readline with an undefined filehandle is always a
failure.

Fixes: e97a30e7624d ("lei: fix SIGPIPE on large result sets to pager")
20 months agotest_common: fix excessive wait for GNU tail inotify
Eric Wong [Mon, 20 Nov 2023 07:39:09 +0000 (07:39 +0000)] 
test_common: fix excessive wait for GNU tail inotify

We want to use the filenames tail will watch, not the number of
args passed to the `tail_f' subroutine.

Fixes: 9231d2e7b93f (tests: map CLOFORK->FD_CLOEXEC temporarily for `tail -f')
20 months agoextindex: warn and hint about --gc on bad ibx_id
Eric Wong [Thu, 16 Nov 2023 11:00:20 +0000 (11:00 +0000)] 
extindex: warn and hint about --gc on bad ibx_id

Stale entries from newsgroup name changes (including adding
a `publicinbox.<name>.newsgroup' entry when none existed
before) can wreak havoc during a --reindex.  So give the
hint to users about running -extindex with --gc to clean
up stale entries.

20 months agolei q|up|convert: common finish_output to detect errors
Eric Wong [Wed, 15 Nov 2023 09:21:45 +0000 (09:21 +0000)] 
lei q|up|convert: common finish_output to detect errors

We need to consistently check the exit code of pigz|gzip|xz|bzip2
when writing to compressed mboxes (or bad storage).

20 months agolei: avoid extra fork for v2 outputs
Eric Wong [Wed, 15 Nov 2023 09:21:44 +0000 (09:21 +0000)] 
lei: avoid extra fork for v2 outputs

We've always forced LeiToMail to only have one process for v2
outputs anyways since v2 has its own sharding and IPC.  Thus we
can use the single LeiToMail process directly to avoid extra IPC
overhead.

20 months agolei convert: fix repeat and idempotent v2 output
Eric Wong [Wed, 15 Nov 2023 09:21:43 +0000 (09:21 +0000)] 
lei convert: fix repeat and idempotent v2 output

We should be able to treat v2 outputs just like any other mail
format, with the exception that content dedupe is always
enforced by the v2 format.

This allows users hosting v2 public-inboxes to catch up broken
synchronization from alternate archives such as the mbox
archives hosted by https://lists.gnu.org/

Link: https://public-inbox.org/meta/20231114-hypersonic-papaya-starling-e1cfc8@nitro/
20 months agolei: fix idempotent STDERR redirect in workers
Eric Wong [Wed, 15 Nov 2023 09:21:42 +0000 (09:21 +0000)] 
lei: fix idempotent STDERR redirect in workers

This is needed to support forking from already-forked lei workers
and $lei->{2} is already STDERR.

Fixes: e015c3742f91 (lei: use autodie where appropriate, 2023-10-17)
20 months agoxap_helper_cxx: accept leading spaces from pkg-config
Eric Wong [Wed, 15 Nov 2023 08:24:22 +0000 (08:24 +0000)] 
xap_helper_cxx: accept leading spaces from pkg-config

Eric Wong <e@80x24.org> wrote:
> Avoid mixing autodie use in different scopes since it's likely
> to cause problems like it did in Gcf2.  While none of these
> fix known problems with test cases, it's likely worthwhile to
> avoid it anyways to avoid future surprises.

>  lib/PublicInbox/XapHelperCxx.pm | 18 ++++++++----------

That XapHelperCxx change was totally necessary for running the
C++ build on CentOS 7.x (but the test is auto-skipped on any
build failure), as is this one:

--------8<--------
Subject: [PATCH] xap_helper_cxx: accept leading spaces from pkg-config

pkg-config 0.27.1 and xapian14-core-devel (1.4.24-1.el7) on
CentOS 7.x will print a leading space when running
`pkg-config --libs --cflags xapian-core'.  This leading
space creates an empty string when `split' with /\s+/ as
a pattern.  Instead, use the documented ' ' (SP) character
to put split into "awk mode" which eats leading (and
redundant) spaces and tabs.

20 months agotreewide: more autodie safety fixes for older Perl
Eric Wong [Wed, 15 Nov 2023 04:32:39 +0000 (04:32 +0000)] 
treewide: more autodie safety fixes for older Perl

Avoid mixing autodie use in different scopes since it's likely
to cause problems like it did in Gcf2.  While none of these
fix known problems with test cases, it's likely worthwhile to
avoid it anyways to avoid future surprises.

For Process::IO, we'll add some additional tests in t/io.t
to ensure we don't get unintended exceptions for try_cat.

20 months agogcf2: fix autodie usage for older Perl
Eric Wong [Wed, 15 Nov 2023 04:32:38 +0000 (04:32 +0000)] 
gcf2: fix autodie usage for older Perl

At least on Perl v5.16.3 on CentOS 7.x, use-ing autodie within
BEGIN {} affects all subroutines in that package, too.  So just
use autodie at the top-level and rely on CORE::* and try_cat
to handle cases where autodie isn't desired.

20 months agogcf2client: add alias for PublicInbox::Git::fail
Eric Wong [Wed, 15 Nov 2023 04:32:37 +0000 (04:32 +0000)] 
gcf2client: add alias for PublicInbox::Git::fail

Ensure we can ->fail properly from other subs we can within
Gcf2Client.  This doesn't fix the test failures on CentOS 7.x,
but tries to make it easier to fix underlying problems and
report OOM errors and other things which the test suite doesn't
touch on.

20 months agods: run @post_loop_do if any user-queued events run
Eric Wong [Tue, 14 Nov 2023 22:46:57 +0000 (22:46 +0000)] 
ds: run @post_loop_do if any user-queued events run

This ensures we can notice shutdown events in one-shot scripts
like -cindex (and eventually -clone/-fetch/-compact) without
forcing another real event to fire.

20 months agocindex: fix test when missing time(1) executable
Eric Wong [Wed, 15 Nov 2023 05:55:49 +0000 (05:55 +0000)] 
cindex: fix test when missing time(1) executable

It was only there for development purposes because associate is
slow, but it causes the test to get stuck on systems where it's
not available.  So remove it and just call join(1posix).

Note: this is not the `time' builtin found in shells, this
executable shows memory and pagefault info (and more with the
`-v' switch).  Unfortunately, it's not installed on many systems
despite being widely-packaged.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
20 months agot/lei-import: account for more verbose error
Eric Wong [Wed, 15 Nov 2023 01:04:57 +0000 (01:04 +0000)] 
t/lei-import: account for more verbose error

Perl 5.16.3 on CentOS seems more verbose in one of the EIO
tests.  Relax the regexp so we can account for extra errors
reported by Perl.

20 months agolei: use -signal numbers for old Perl
Eric Wong [Wed, 15 Nov 2023 01:04:56 +0000 (01:04 +0000)] 
lei: use -signal numbers for old Perl

Unlike modern Perls, Perl 5.16.3 on CentOS doesn't accept
negative string signals like "-TERM" .

This only became a problem since commit b231d91f42d7
(treewide: enable warnings in all exec-ed processes)
made our code stricter by enabling more warnings.
In both cases, the kill is probably unnecessary and safe
to remove since we can rely on closing sockets to drop
processes.

20 months agoTestCommon: older strace does not have --version
Konstantin Ryabitsev [Tue, 14 Nov 2023 20:16:37 +0000 (15:16 -0500)] 
TestCommon: older strace does not have --version

The tests will check for strace >= 4.16, but version 4.24 that I have
does not accept --version, only -V. This works for both older and newer
strace, so switch to using "strace -V" for the check.

Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
20 months agoconfig: avoid eidx_key and newsgroup conflicts
Eric Wong [Tue, 14 Nov 2023 00:32:20 +0000 (00:32 +0000)] 
config: avoid eidx_key and newsgroup conflicts

Start lowercasing newsgroup names automatically since uppercase
names are incompatible with IMAP and POP3 and also causes
problems with both -extindex and -cindex.

We'll also warn on eidx_key and newsgroup conflicts to avoid
sometimes subtle breakage when using -extindex and -cindex.

20 months agocindex: fix missing semicolon on broken $GIT_DIR/objects
Eric Wong [Tue, 14 Nov 2023 18:58:41 +0000 (18:58 +0000)] 
cindex: fix missing semicolon on broken $GIT_DIR/objects

Noticed while working on another feature...

20 months agocindex: support --associate-aggressive shortcut
Eric Wong [Mon, 13 Nov 2023 13:15:51 +0000 (13:15 +0000)] 
cindex: support --associate-aggressive shortcut

This is shorthand to enabling --associate with the most
aggressive (and time-consuming) options available, starting from
the Unix epoch and having an unlimited window to join on.

20 months agocindex: rename associate-max => window
Eric Wong [Mon, 13 Nov 2023 13:15:50 +0000 (13:15 +0000)] 
cindex: rename associate-max => window

"window" is probably a better term since it's an inexact thing
to match on.

20 months agocindex: do not guess integer maximum for Xapian
Eric Wong [Mon, 13 Nov 2023 13:15:49 +0000 (13:15 +0000)] 
cindex: do not guess integer maximum for Xapian

We can return an array to allow the caller to omit the internal
`-m' arg entirely.  We'll also allow any non-positive values to
mean there's no limit; and we'll defer the "unlimited" case to
the XapHelper implementation.  This frees us of having to deal
with mismatches between Perl and Xapian if Xapian was compiled
with 64-bit docid support and we're stuck on a 32-bit Perl
build.

20 months agoxap_helper: better variable naming for key buffer
Eric Wong [Mon, 13 Nov 2023 13:15:48 +0000 (13:15 +0000)] 
xap_helper: better variable naming for key buffer

We'll use `kbuf' for the search object key, since we already use
the `fbuf' term in `struct fbuf'.  This also adds an extra check
for open_memstream(3) failures in case of ENOMEM.

20 months agoxap_helper: stricter and harsher error handling
Eric Wong [Mon, 13 Nov 2023 13:15:47 +0000 (13:15 +0000)] 
xap_helper: stricter and harsher error handling

We'll require an error stream for dump_ibx and dump_roots
commands; they're too important to ignore.  Instead of writing
code to provide diagnostics for errors, rely on abort(3) and the
-ggdb3 compiler flag to generate nice core dumps for gdb since
all commands sent to xap_helper are from internal users.
We'll even abort on most usage errors since they could be
bugs in split2argv or our use of getopt(3).

We'll also just exit on ENOMEM errors since it's the easiest way
to recover from those errors by starting a new process which
closes all open Xapian DB handles.

20 months agocidx_xap_helper_aux: complain about truncated inputs
Eric Wong [Mon, 13 Nov 2023 13:15:46 +0000 (13:15 +0000)] 
cidx_xap_helper_aux: complain about truncated inputs

This will help us notice bugs and system resource limitations
sooner rather than later.

20 months agoxap_helper: Perl dump_ibx respects `-m MAX'
Eric Wong [Mon, 13 Nov 2023 13:15:45 +0000 (13:15 +0000)] 
xap_helper: Perl dump_ibx respects `-m MAX'

The C++ version does, so the Perl/XS version should, too;
even if we intentionally avoid using it right now.

20 months agocindex: delay associate until prune+indexing finish
Eric Wong [Mon, 13 Nov 2023 13:15:44 +0000 (13:15 +0000)] 
cindex: delay associate until prune+indexing finish

Prune can get rid of invalid commits while indexing can add new
candidates for association, so we don't dump coderepo roots for
association until those are squared away.  However, we can dump
inbox info since we don't touch inboxes while -cindex is running.

20 months agocindex: imply --all with --associate w/o -I/--only
Eric Wong [Mon, 13 Nov 2023 13:15:43 +0000 (13:15 +0000)] 
cindex: imply --all with --associate w/o -I/--only

I just forgot to use --all with --associate and it wasn't
easily apparent what was wrong.  We'll also show some extra
progress while we're at it.

20 months agospawn: don't append to scalarrefs on stdout/stderr
Eric Wong [Mon, 13 Nov 2023 13:15:42 +0000 (13:15 +0000)] 
spawn: don't append to scalarrefs on stdout/stderr

None of our current code relies on it, and I can't imagine it's
something we'd need in the future, actually...  This keeps the
door open for relying more on Spawn in TestCommon.

20 months agotreewide: update read_all to avoid eof|close checks
Eric Wong [Mon, 13 Nov 2023 13:15:41 +0000 (13:15 +0000)] 
treewide: update read_all to avoid eof|close checks

read_all can be expanded to support FIFOs/pipes/sockets where
read-until-EOF behavior is desired.  We can also rely on
wantarray to support splitting on EOL markers, but it's
hard-coded to support only `$/ eq "\n"' since (AFAIK)
it's the only way we use the wantarray form `readline'.

20 months agoxap_client: spawn C++ xap_helper directly
Eric Wong [Mon, 13 Nov 2023 13:15:40 +0000 (13:15 +0000)] 
xap_client: spawn C++ xap_helper directly

No need to suffer through an extra dose of slow Perl load times
when we can drive the build in the big parent Perl process and
get the executable path name to pass to spawn directly.

20 months agoxap_helper_cxx: use -pipe by default in CXXFLAGS
Eric Wong [Mon, 13 Nov 2023 13:15:39 +0000 (13:15 +0000)] 
xap_helper_cxx: use -pipe by default in CXXFLAGS

-ggdb3 is already used for g++ and clang, and -pipe is supported
by clang even if it's a no-op.  So just use it to speed up g++
since it saves me 30-40ms.

We'll also get rid of the explicit `-O0' since it's the default
for both clang and g++.

20 months agoxap_helper_cxx: make the build process ccache-friendly
Eric Wong [Mon, 13 Nov 2023 13:15:38 +0000 (13:15 +0000)] 
xap_helper_cxx: make the build process ccache-friendly

We need to have stable filenames and separate compilation
from the linkage stage for ccache to hit.  So avoid the use
of a temporary directory and instead rely on a lock file to
guard against parallel builds.

20 months agoxap_helper_cxx: use write_file helper
Eric Wong [Mon, 13 Nov 2023 13:15:37 +0000 (13:15 +0000)] 
xap_helper_cxx: use write_file helper

PublicInbox::IO already gets loaded by PublicInbox::Spawn, so
there's no avoiding it even if we want fast startup time :<
But startup time for this piece will be less relevant in the
near future...

20 months agocindex: use `local' for pipes between processes
Eric Wong [Mon, 13 Nov 2023 13:15:36 +0000 (13:15 +0000)] 
cindex: use `local' for pipes between processes

We can let these pipes get auto-closed upon leaving the process
subroutine scope.

20 months agotmpfile: check `stat' errors, use autodie for unlink
Eric Wong [Mon, 13 Nov 2023 13:15:35 +0000 (13:15 +0000)] 
tmpfile: check `stat' errors, use autodie for unlink

`stat' can fail due to bugs on our end or ENOMEM, but there's
no autodie support for it.  So just die if `unlink' fails, since
the FS wouldn't be usable for tmpfiles in that state, anyways.