]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
2 years agodaemon: make SO_ACCEPTFILTER a shared variable
Eric Wong [Fri, 1 Oct 2021 09:54:39 +0000 (09:54 +0000)]
daemon: make SO_ACCEPTFILTER a shared variable

Constant subroutines use more memory and there's no need to
optimize it for inlining since it's only used at startup.

2 years agolistener: switch to level-triggered epoll
Eric Wong [Fri, 1 Oct 2021 09:54:38 +0000 (09:54 +0000)]
listener: switch to level-triggered epoll

On second thought, the ->requeue + accept retry code path isn't
worth the userspace complexity and overhead.  Level-triggered
epoll has always annoyed me since it takes an inefficient code
path in the kernel; but taking our less-efficient code path in
Perl seems even worse.  We also need to take load distribution
into account for multi-worker systems.

2 years agodoc: lei-security: some more updates
Eric Wong [Fri, 1 Oct 2021 09:54:37 +0000 (09:54 +0000)]
doc: lei-security: some more updates

Virtual users will probably be used for read-write IMAP/JMAP
support.  The potential for various kernel/hardware bugs and
attacks also needs to be highlighted.

2 years agosearch_view: various navigation tweaks
Eric Wong [Fri, 1 Oct 2021 02:10:27 +0000 (02:10 +0000)]
search_view: various navigation tweaks

This improves the "&x=t" navigation between the thread overview
(skeleton) section at the bottom and jumping back to the top for
the mbox download form.  The "--links below ..." text ought to
be helpful for users unfamiliar with the /$MSGID/T/ and /$MSGID/t/
views.

2 years agogit: shorten --git-dir= in CLI with chdir in spawn
Eric Wong [Wed, 29 Sep 2021 21:25:20 +0000 (21:25 +0000)]
git: shorten --git-dir= in CLI with chdir in spawn

Long pathnames are difficult to read and distinguish in ps(1)
output.  Deep paths can also slow down pathname resolution
when dealing with loose objects, so we put "cat-file --batch"
deeper into the directory tree.

Since v2 processes are in the form of $INBOXDIR/all.git, keep
the basename of $INBOXDIR in --git-dir= so it's easy to
distinguish between processes just by looking at ps(1).

While "git -C" also exists, it's only present in git 1.8.5+.
We also need to keep in mind the "directory" pointed to by
--git-dir= need not be a directory (nor a symlink pointing
to one).

This reduces pathname resolution overhead for v1 and v2 inbox
git processes, but unfortunately not for extindex since that
needs to store alternates as absolute paths.

2 years agods: drop ::later support
Eric Wong [Wed, 29 Sep 2021 12:40:47 +0000 (07:40 -0500)]
ds: drop ::later support

add_uniq_timer seems sufficient, and we'll drop the last
user of ::later (IMAP) and switch to unique timers.

2 years agods: simplify idle time expiry, slightly
Eric Wong [Wed, 29 Sep 2021 12:40:46 +0000 (07:40 -0500)]
ds: simplify idle time expiry, slightly

While it doesn't look like $EXPMAP can be populated in
non-obvious ways via ->DESTROY, it still makes sense to keep it
close to some of our other code around cleanup to reduce
the likelyhood of subtle bugs in case semantics change..

2 years agot/solver_git: fix test to work with git <2.29
Eric Wong [Wed, 29 Sep 2021 03:02:54 +0000 (03:02 +0000)]
t/solver_git: fix test to work with git <2.29

'git diff --abbrev=40' did not abbreviate /^index / lines of
diff output with git <2.29, and 40 will be insufficient for
SHA-256.  --full-index has been around since 2005, so it's safe
to rely on.

Tested git version 2.20.0 (Debian buster).

Fixes: 751df49e7db8ba77 ("lei rediff: add --drq and --dequote-only")
2 years agoinbox: do not vivify {-repo_objs} during cleanup
Eric Wong [Wed, 29 Sep 2021 00:14:28 +0000 (00:14 +0000)]
inbox: do not vivify {-repo_objs} during cleanup

This caused config->repo_objs to not fill in {-repo_objs}
properly before starting solver.

Reported-by: Kyle Meyer <kyle@kyleam.com>
Link: https://public-inbox.org/meta/87o88cqobd.fsf@kyleam.com/
Fixes: 63d7b8ceee55a34 ("daemons: revamp periodic cleanup task")
2 years agoinbox: drop memoization/preload, cleanup expires caches
Eric Wong [Tue, 28 Sep 2021 23:11:06 +0000 (23:11 +0000)]
inbox: drop memoization/preload, cleanup expires caches

cloneurl, description, and base_url are no longer memoized.  The
non-$env form of base_url is rare in WWW, and is fast enough to
not require memoization.

cloneurl and description are now expired during cleanup,
allowing admins to change these files without restarting
(or SIGHUP).

-altid_map is no longer cached nor memoized at all, since the
endpoint(s) which hit it seem rarely accessed.

nntp_url and imap_url are now cached (instead of memoized) in
case an inbox is unvisited for a long time.  They remain cached
since the truthiness check gets called in every per-inbox HTML
page, which can potentially be expensive.

2 years agoinbox: rewrite cleanup to be more aggressive
Eric Wong [Tue, 28 Sep 2021 23:11:05 +0000 (23:11 +0000)]
inbox: rewrite cleanup to be more aggressive

Avoid relying on a giant cleanup hash and instead use the new
DS->add_uniq_timer API to amortize the pause times associated
with having to cleanup many inboxes.  We can also use smaller
intervals for this, as well.

We now discard SQLite DB handles at cleanup.  Each of these can
use several megabytes of memory, which adds up with
hundreds/thousands of inboxes.  Since per-inbox access intervals
are unpredictable and opening an SQLite handle is relatively
inexpensive, release memory more aggressively to avoid the heap
having to hit swap.

2 years agowww: do not bump {over} refcnt on long responses
Eric Wong [Tue, 28 Sep 2021 23:11:04 +0000 (23:11 +0000)]
www: do not bump {over} refcnt on long responses

SQLite files may be replaced or removed by admins while
generating a large threads or mailbox responses.  Ensure we
don't hold onto DBI handles and associated file descriptors
past their cleanup.

2 years agowww+httpd: lower priority of large mbox downloads
Eric Wong [Tue, 28 Sep 2021 07:53:49 +0000 (07:53 +0000)]
www+httpd: lower priority of large mbox downloads

While each git blob request is treated fairly w.r.t other git
blob requests, responses triggering thousands of git blob
requests can still noticeably increase latency for
less-expensive responses.

Move large mbox results and the nasty all.mbox endpoint to
a low priority queue which only fires once per-event loop
iteration.  This reduces the response time of short HTTP
responses while many gigantic mboxes are being downloaded
simultaneously, but still maximizes use of available I/O
when there's no inexpensive HTTP responses happening.

This only affects PublicInbox::WWW users who use
public-inbox-httpd, not generic PSGI servers.

2 years agodoc: lei-rediff: grammar fixes for --drq and --dequote-only
Kyle Meyer [Mon, 27 Sep 2021 23:53:56 +0000 (19:53 -0400)]
doc: lei-rediff: grammar fixes for --drq and --dequote-only

2 years agolei completion: workaround old Perl bug
Eric Wong [Mon, 27 Sep 2021 21:05:45 +0000 (16:05 -0500)]
lei completion: workaround old Perl bug

While `$argv[-1]' is `undef' on an empty @argv, using `$argv[-1]'
as a subroutine argument would fail incorrectly with:

    Modification of non-creatable array value attempted, subscript -1 at ...

...even though we'd never attempt to modify @_ itself in the
subroutines being called.  Work around the bug (tested on
5.16.3) by passing `undef' explicitly when `$argv[-1]' is
already `undef'.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210927124056.kj5okiefvs4ztk27@meerkat.local/
2 years agot/lei-index: IMAP and NNTP dependencies are optional
Eric Wong [Mon, 27 Sep 2021 21:05:44 +0000 (16:05 -0500)]
t/lei-index: IMAP and NNTP dependencies are optional

"lei index" support for IMAP and NNTP is incomplete, so there's
no point in requiring them.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210927124056.kj5okiefvs4ztk27@meerkat.local/
2 years agofetch: support running as root
Eric Wong [Mon, 27 Sep 2021 21:05:43 +0000 (16:05 -0500)]
fetch: support running as root

The "-w" perlop always succeeds as root, so we need to check
st_mode for writability bits to detect directories we shouldn't
write to.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210927124056.kj5okiefvs4ztk27@meerkat.local/
2 years agot/cmd_ipc: allow extra errors and add diagnostics
Eric Wong [Mon, 27 Sep 2021 18:35:36 +0000 (13:35 -0500)]
t/cmd_ipc: allow extra errors and add diagnostics

Apparently, sendmsg can fail in less common ways when
network buffers are gigantic.  Add some diagnostics for
future failures, as well.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210927124056.kj5okiefvs4ztk27@meerkat.local/
2 years agoxt/net_writer_imap: env knobs for compress/debug/proxy
Eric Wong [Mon, 27 Sep 2021 09:23:15 +0000 (02:23 -0700)]
xt/net_writer_imap: env knobs for compress/debug/proxy

It can be useful to test with some of these, but we can't enable
them universally for all servers (and debug + compress is gross)

2 years agoconfig: get_1: use full parameter name
Eric Wong [Mon, 27 Sep 2021 07:53:07 +0000 (02:53 -0500)]
config: get_1: use full parameter name

Instead of passing the prefix section and key separately, pass
them together as is commonly done with git-config(1) usage as
well as our ->get_all API.  This inconsistency in the get_1 API
is a needless footgun and confused me a bit while working on
"lei up" the other week.

2 years agolei rediff: add --drq and --dequote-only
Eric Wong [Mon, 27 Sep 2021 04:59:31 +0000 (04:59 +0000)]
lei rediff: add --drq and --dequote-only

More switches which can be useful for users who pipe from text
editors.  --drq can be helpful while writing patch review email
replies, and perhaps --dequote-only, too.

2 years agolei rediff: quiet warnings from Import and Eml
Eric Wong [Mon, 27 Sep 2021 04:59:30 +0000 (04:59 +0000)]
lei rediff: quiet warnings from Import and Eml

lei rediff is expected to see partial patch fragments and such,
so silence warnings when something isn't exactly a valid email
message.

2 years agonet_reader: drop support for IgnoreSizeErrors option
Eric Wong [Sun, 26 Sep 2021 21:25:47 +0000 (21:25 +0000)]
net_reader: drop support for IgnoreSizeErrors option

Only the ->message_string method of Mail::IMAPClient uses it,
and we have no intention of using ->message_string outside
of tests.

2 years agolei: ensure refresh_watches isn't called from workers
Eric Wong [Sun, 26 Sep 2021 05:38:19 +0000 (22:38 -0700)]
lei: ensure refresh_watches isn't called from workers

Only the top-level lei-daemon will do inotify/kevent.

2 years agot/run.perl: less confusing error reporting
Eric Wong [Sun, 26 Sep 2021 01:42:38 +0000 (01:42 +0000)]
t/run.perl: less confusing error reporting

The $sigchld handler was reporting the last test (successful or
not) for a given PID in case a worker dies prematurely.
Instead, redisplay all failed test in $run_log to ensure the
report only shows failed tests, and not the last started (and
possibly successful) one.

2 years agoinbox: cloneurl: avoid undef to hash table value
Eric Wong [Sun, 26 Sep 2021 01:42:29 +0000 (01:42 +0000)]
inbox: cloneurl: avoid undef to hash table value

This saves us some memory for the hash slot in the common case
the `cloneurl' file doesn't exist.

2 years agolei -f reply: fix Cc: header combining
Eric Wong [Sun, 26 Sep 2021 01:42:06 +0000 (01:42 +0000)]
lei -f reply: fix Cc: header combining

When combining lines from To: and Cc: headers, ", " needs to be
used to separate them.

2 years agowww_listing: support /all/ search as a 302 redirect
Eric Wong [Sun, 26 Sep 2021 01:30:47 +0000 (01:30 +0000)]
www_listing: support /all/ search as a 302 redirect

This allows users to search /all/ from the top-level WwwListing
without extra manual steps, although there's still extra network
roundtrips incurred.

No vertical whitespace is added, and there's no clumsy radio
buttons nor menus to deal with.  Users only have to use a
different <input type=submit /> button.  I forgot how to do this
until I realized we already do something similar with multiple
submit buttons for threaded vs non-threaded mboxrd.gz downloads.

Link: https://public-inbox.org/meta/20210827120845.29682-1-e@80x24.org/
2 years agolei note-event: ignore kw_changed exceptions
Eric Wong [Sun, 26 Sep 2021 00:02:32 +0000 (00:02 +0000)]
lei note-event: ignore kw_changed exceptions

The note-event worker may see changes before a Xapian shard
commit happens, meaning keyword lookups fail as a result.
Just emit the request to the lei/store worker since it's a
fairly cheap operation at this point.

We'll try harder to look for kw changes, too, since
deduplication changes may lead to multiple docids being
resolved for a single message.

2 years agosearch: avoid setting undef hashtable entries
Eric Wong [Sat, 25 Sep 2021 22:16:45 +0000 (22:16 +0000)]
search: avoid setting undef hashtable entries

`undef' entries still take up a slot in the hash table, and
cause the `exists' check to false-positive in ->cleanup_shards.
This should fully fix the (innocuous) messages introduced in
commit 63d7b8ce (daemons: revamp periodic cleanup task, 2021-09-23)

2 years agoextmsg: search_partial: use ->isrch if available
Eric Wong [Sat, 25 Sep 2021 22:16:44 +0000 (22:16 +0000)]
extmsg: search_partial: use ->isrch if available

This allows us to avoid creating ibx->{search}->{xdb} at this
spot by using an `undef' value.  This is a step towards
eliminating the innocuous "/path/to/inboxdir/xap15 has no shards"
messages introduced in commit 63d7b8ce (daemons: revamp
periodic cleanup task, 2021-09-23)

2 years agolei ls-external: split into separate file
Eric Wong [Sat, 25 Sep 2021 08:49:45 +0000 (08:49 +0000)]
lei ls-external: split into separate file

This was written before we had auto-loading and rarely used.

2 years agolei add-external: split into separate file
Eric Wong [Sat, 25 Sep 2021 08:49:44 +0000 (08:49 +0000)]
lei add-external: split into separate file

Also was written before we had auto-loading and rarely used.

2 years agolei forget-external: split into separate file
Eric Wong [Sat, 25 Sep 2021 08:49:43 +0000 (08:49 +0000)]
lei forget-external: split into separate file

This was written before we had auto-loading, and forget-external
should be a rarely-used command that's not worth loading at
startup.  Do some golfing while we're in the area, too.

2 years agodoc: lei-rm: remove unnecessary -F values
Eric Wong [Sat, 25 Sep 2021 07:08:38 +0000 (07:08 +0000)]
doc: lei-rm: remove unnecessary -F values

-F is really only useful for distinguishing between mbox
variants and single message/rfc822 files.  URLs and
directory-based formats can be auto-detected easily enough.

2 years agolei: make pkt_op easier-to-use and understand
Eric Wong [Sat, 25 Sep 2021 06:17:54 +0000 (06:17 +0000)]
lei: make pkt_op easier-to-use and understand

Since switching to SOCK_SEQUENTIAL, we no longer have to use
fixed-width records to guarantee atomic reads.  Thus we can
maintain more human-readable/searchable PktOp opcodes.

Furthermore, we can infer the subroutine name in many cases
to avoid repeating ourselves by specifying a command-name
twice (e.g. $ops->{CMD} => [ \&CMD, $obj ]; can now simply be
written as: $ops->{CMD} => [ $obj ]  if CMD is a method of
$obj.

2 years agolei2mail: augment_inprogress: guard against closed FDs
Eric Wong [Sat, 25 Sep 2021 05:49:45 +0000 (05:49 +0000)]
lei2mail: augment_inprogress: guard against closed FDs

I'm not sure what caused it, but $err was undef and caused print
to fail, leading to an event loop error.  Guard the timer with
an eval and assume warn() can't trigger an event loop failure.

2 years agolei: restore old sigmask before daemon exit
Eric Wong [Sat, 25 Sep 2021 05:49:44 +0000 (05:49 +0000)]
lei: restore old sigmask before daemon exit

If the event loop fails, we want blocking waitpid (wait4) calls
to be interruptible with SIGTERM via "kill $PID" rather than
SIGKILL.  Though a failing event loop is something we should
avoid...

2 years agolei up: show timezone offset with localtime
Eric Wong [Sat, 25 Sep 2021 05:49:43 +0000 (05:49 +0000)]
lei up: show timezone offset with localtime

Sometimes a user (e.g. me) isn't really sure what timezone
they're in...

2 years agodoc: lei: manpages for export-kw and refresh-mail-sync
Eric Wong [Fri, 24 Sep 2021 12:51:09 +0000 (12:51 +0000)]
doc: lei: manpages for export-kw and refresh-mail-sync

Something is better than nothing.

2 years agodoc: lei-index: remove --stdin, reword -F
Eric Wong [Fri, 24 Sep 2021 12:51:08 +0000 (12:51 +0000)]
doc: lei-index: remove --stdin, reword -F

lei-index really only works for Maildir, at the moment.

2 years agodoc: lei-overview: implicit stdin, correct Inline::C notes
Eric Wong [Fri, 24 Sep 2021 12:51:07 +0000 (12:51 +0000)]
doc: lei-overview: implicit stdin, correct Inline::C notes

Implicit stdin based on standard input being a pipe or regular
file is here to stay, so save users the trouble of typing '-'
or '--stdin'.

Inline::C is required as of commit 1d6e1f9a6a66 (lei: require
Socket::MsgHdr or Inline::C, drop oneshot, 2021-05-26); but
Socket::MsgHdr still gives a noticeable improvement in bash
completion speed.

Also, spell-out "MESSAGE-ID" since "MID" is actually not a
common abbreviation ("MSGID" is used by RFC 3977 and several
other RFCs, I recall).

2 years agodoc: lei blob+rediff+p2q: add notes about git directory
Eric Wong [Fri, 24 Sep 2021 12:51:06 +0000 (12:51 +0000)]
doc: lei blob+rediff+p2q: add notes about git directory

Try to clarify these commands are intended to be useful for
git-using (usually software) projects (and not the bare git
repos we use internally).

We'll also document some commonly useful git-diff switches
in the lei-rediff man page to highlight the usefulness
of the command.

2 years agot/v2mirror: check dependencies for legacy test
Eric Wong [Sat, 25 Sep 2021 03:21:01 +0000 (03:21 +0000)]
t/v2mirror: check dependencies for legacy test

We still need Email::MIME to test against old revisions.
We'll also depend on the revision just prior to the
manifest.js.gz introduction to avoid loading Danga::Socket,
since it was getting loaded even with `plackup'.

Finally, we'll disable Inline::C usage with old Spawn.pm
since our old code included alloca.h, which is not
portable to FreeBSD.

2 years agofetch: support v2 w/o manifest on old WWW
Eric Wong [Fri, 24 Sep 2021 10:56:45 +0000 (10:56 +0000)]
fetch: support v2 w/o manifest on old WWW

There may still be pre-manifest.js.gz versions of
PublicInbox::WWW running and serving v2 inboxes.

While -clone and "add-external --mirror" were working, -fetch
was failing due to 301 redirect to $INBOX_URL/manifest.js.gz/
and not the expected 404.  Update the code to deal with a JSON
decode error (from the 301) and ensure v2 epochs detection is
correct (and not using a shadowed variable).

2 years agoclone|fetch|--mirror: cull manifest in partial mirrors
Eric Wong [Fri, 24 Sep 2021 10:56:44 +0000 (10:56 +0000)]
clone|fetch|--mirror: cull manifest in partial mirrors

This makes it easier for users to enable fetching on a
previously read-only epoch.  Prior to this change, users were
required to delete manifest.js.gz in addition to adding the
writable bit.  Now, they just have to "chmod +w $EPOCH_DIR".

2 years agoclone|--mirror: fix and test against pre-manifest WWW
Eric Wong [Fri, 24 Sep 2021 10:56:43 +0000 (10:56 +0000)]
clone|--mirror: fix and test against pre-manifest WWW

There may still be pre-manifest.js.gz versions of PublicInbox::WWW.
running and serving v2 inboxes.

Since $INBOX_URL/manifest.js.gz was not understood, it was
assumed to be a Message-ID and 301-ed to
"$INBOX_URL/manifest.js.gz/" with a trailing slash, so our 404
checks were invalid.  Update our fallbacks to deal with 301
by catching JSON decoding errors to trigger HTML scraping.

For HTML parsing, be sure to not be fooled by potential
user-generated content and only scan the part after the last
<hr>.

We also need to avoid propagating $? from curl unnecessarily
when we can continue safely.

Finally, update v2mirror.t with tests to use PublicInbox::WWW
from our "v1.1.0-pre1" tag to ensure these code paths get tested

2 years agofetch: fix skipping with multi-epoch inboxes
Eric Wong [Fri, 24 Sep 2021 10:56:42 +0000 (10:56 +0000)]
fetch: fix skipping with multi-epoch inboxes

We need to check every epoch for writability, so don't
break out of the loop when we find a URL.

2 years agoclone|--mirror: support --epoch=RANGE for partial clones
Eric Wong [Fri, 24 Sep 2021 10:56:41 +0000 (10:56 +0000)]
clone|--mirror: support --epoch=RANGE for partial clones

Partial (v2) clones should be useful addition for users wanting
to conserve storage while having fast access to recent messages.

Continuing work started in 876e74283ff3 (fetch: ignore
non-writable epoch dirs, 2021-09-17), this creates bare,
read-only epoch git repos.  These git repos have the remotes
pre-configured, but does not fetch any objects.

The goal is to allow users to set the writable bit on a
previously-skipped epoch and start fetching it.

Shell completion support may not be necessary given how short
the epoch ranges are, here.

Cc: Luis Chamberlain <mcgrof@kernel.org>
Link: https://public-inbox.org/meta/20210917002204.GA13112@dcvr/T/#u
2 years agolei_xsearch: use localtime for user message
Eric Wong [Thu, 23 Sep 2021 10:37:42 +0000 (10:37 +0000)]
lei_xsearch: use localtime for user message

It's probably least confusing for user-facing messages to
display times in the user's configured timezone.  I considered
appending "UTC" to the message and sticking with gmtime(), too,
but this output isn't intended to be web-cache friendly nor
expect users from across multiple timezones to view the same
output.

2 years agolei: common --all[=remote|local] help message
Eric Wong [Thu, 23 Sep 2021 10:36:22 +0000 (10:36 +0000)]
lei: common --all[=remote|local] help message

It helps to be consistent and reduce the learning curve, here.

2 years agoxcpdb: avoid race when shards are added
Eric Wong [Thu, 23 Sep 2021 05:53:03 +0000 (05:53 +0000)]
xcpdb: avoid race when shards are added

It's possible for the rename() sequence to cause read-only
daemons using ->xdb_shards_flat to load an incomplete set of
contiguous shards and get invalid docids for search results.

With this change, we favor the case where search is momentarily
unavailable rather than giving wrong results during the small
window where Xapcmd->commit_changes runs.

2 years agoxcpdb: -R$SHARDS creates new shards with correct perms
Eric Wong [Thu, 23 Sep 2021 05:53:02 +0000 (05:53 +0000)]
xcpdb: -R$SHARDS creates new shards with correct perms

"Correct" meaning the permissions match that of the parent
xap15 or ei15 directory.

2 years agotest_common: reset umask on non-forking run_script
Eric Wong [Thu, 23 Sep 2021 05:53:01 +0000 (05:53 +0000)]
test_common: reset umask on non-forking run_script

public-inbox-init sets umask for git <2.1.0, so our fork+exec
replacement needs to restore the original umask of the "parent".

2 years agodaemons: revamp periodic cleanup task
Eric Wong [Thu, 23 Sep 2021 00:46:25 +0000 (00:46 +0000)]
daemons: revamp periodic cleanup task

Neither Inboxes nor ExtSearch objects were retrying correctly
when there are live git processes, but the inboxes were getting
rescanned for search or other reasons.  Ensure the scan retries
eventually if there's live processes.

We also need to update the cleanup task to detect Xapian shard
count changes, since Xapian ->reopen is enough to detect any
other Xapian changes.  Otherwise, we just issue an inexpensive
->reopen call and let Xapian check whether there's anything
worth reopening.

This also lets us eliminate the Devel::Peek dependency.

2 years agogcf2 + extsearch: check for unlinked files on Linux
Eric Wong [Wed, 22 Sep 2021 09:45:17 +0000 (09:45 +0000)]
gcf2 + extsearch: check for unlinked files on Linux

Check for unlinked mmap-ed files via /proc/$PID/maps every 60s
or so.

ExtSearch (extindex) is compatible-enough with Inbox objects to
be wired into the old per-inbox code, but the startup cost is
projected to be much higher down the line when there's >30K
inboxes, so we scan /proc/$PID/maps for deleted files before
unlinking.  With old Inbox objects, it was (and is) simpler to
just kill processes w/o checking due to the low startup cost
(and non-portability of checking).

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210921144754.gulkneuulzo27qbw@meerkat.local/
2 years agolei: drop redundant WQ EOF callbacks
Eric Wong [Wed, 22 Sep 2021 02:24:35 +0000 (02:24 +0000)]
lei: drop redundant WQ EOF callbacks

Redundant code is noise and therefore confusing :<

2 years agolei up: avoid excessively parallel --all
Eric Wong [Wed, 22 Sep 2021 02:24:34 +0000 (02:24 +0000)]
lei up: avoid excessively parallel --all

We shouldn't dispatch all outputs right away since they
can be expensive CPU-wise.  Instead, rely on DESTROY to
trigger further redispatches.

This also fixes a circular reference bug for the single-output
case that could lead to a leftover script/lei after MUA exit.

I'm not sure how --jobs/-j should work when the actual xsearch
and lei2mail has it's own parallelism ("--jobs=$X,$M"), but
it's better than having thousands of subtasks running.

Fixes: b34a267efff7b831 ("lei up: fix --mua with single output")
2 years agoinbox: do not waste hash slot on httpbackend_limiter
Eric Wong [Wed, 22 Sep 2021 02:24:33 +0000 (02:24 +0000)]
inbox: do not waste hash slot on httpbackend_limiter

A few dozen bytes saved here can add up when we have thousands
of inboxes.  It also makes Data::Dumper debug output a bit cleaner.

2 years agolei: dclose: do not close unnecessarily
Eric Wong [Wed, 22 Sep 2021 02:24:32 +0000 (02:24 +0000)]
lei: dclose: do not close unnecessarily

The bit about reap_compress is no longer true since
LeiXSearch->query_done triggers it, instead.  I only noticed
this while working on "lei up".

2 years agoscript/lei: describe purpose of sleep loop
Eric Wong [Wed, 22 Sep 2021 02:24:31 +0000 (02:24 +0000)]
script/lei: describe purpose of sleep loop

It looks dumb, but I'm not about to take a runtime penalty to
use signalfd|EVFILT_SIGNAL, here, either.

2 years agotreewide: fix %SIG localization, harder
Eric Wong [Wed, 22 Sep 2021 02:24:30 +0000 (02:24 +0000)]
treewide: fix %SIG localization, harder

This fixes the occasional t/lei-sigpipe.t infinite loop
under "make check-run".

Link: http://nntp.perl.org/group/perl.perl5.porters/258784
  <CAHhgV8hPbcmkzWizp6Vijw921M5BOXixj4+zTh3nRS9vRBYk8w@mail.gmail.com>
Followup-to: b552bb9150775fe4 ("daemon+watch: fix localization of %SIG for non-signalfd users")
2 years agoipc: do not add "0" to $0 of solo workers
Eric Wong [Wed, 22 Sep 2021 02:24:29 +0000 (02:24 +0000)]
ipc: do not add "0" to $0 of solo workers

It's needless noise and misleads users reading "ps" into
thinking there's more workers when there's only one.

2 years agolei: umask(077) before opening errors.log
Eric Wong [Tue, 21 Sep 2021 09:29:45 +0000 (09:29 +0000)]
lei: umask(077) before opening errors.log

There's a chance some sensitive information (e.g. folder names)
can end up in errors.log, though $XDG_RUNTIME_DIR or
/tmp/lei-$UID/ will have 0700 permissions, anyways.

2 years agoscript/lei: handle SIGTSTP and SIGCONT
Eric Wong [Tue, 21 Sep 2021 09:29:44 +0000 (09:29 +0000)]
script/lei: handle SIGTSTP and SIGCONT

Sometimes it's useful to pause an expensive query or
refresh-mail-sync to do something else.  While lei-daemon and
lei/store can't be paused since they're shared across clients,
per-invocation WQ workers can be paused safely using the
unblockable SIGSTOP.

While we're at it, drop the ETOOMANYREFS hint since it
hasn't been a problem since we drastically reduced FD passing
early in development.

2 years agot/lei-up: use '-q' to silence non-redirected test
Eric Wong [Tue, 21 Sep 2021 09:29:43 +0000 (09:29 +0000)]
t/lei-up: use '-q' to silence non-redirected test

We could redirect, too, but just use -q since we don't care
for the output with run_mode => 0.

2 years agolei q: improve --limit behavior and progress
Eric Wong [Tue, 21 Sep 2021 07:41:59 +0000 (07:41 +0000)]
lei q: improve --limit behavior and progress

Avoid slurping gigantic (e.g. 100000) result sets into a single
response if a giant limit is specified, and instead use 10000
as a window for the mset with a given offset.  We'll also warn
and hint towards about the --limit= switch when the estimated
result set is larger than the default limit.

2 years agolei q: update messages to reflect --save default
Eric Wong [Tue, 21 Sep 2021 07:41:58 +0000 (07:41 +0000)]
lei q: update messages to reflect --save default

I wanted to try --dedupe=none for something, but it failed
since I forgot --no-save :x  So hint users towards --no-save
if necessary.

2 years agosearch: drop reopen retry message
Eric Wong [Tue, 21 Sep 2021 07:41:57 +0000 (07:41 +0000)]
search: drop reopen retry message

It's needless noise in syslogs for daemons and unnecessarily
alarming to users on the command-line.

2 years agolei q: show progress on >1s preparation phase
Eric Wong [Tue, 21 Sep 2021 07:41:56 +0000 (07:41 +0000)]
lei q: show progress on >1s preparation phase

Overwriting existing destinations safe (but slow) by default,
so show a progress message noting what we're doing while
a user waits.

2 years agolei: various completion improvements
Eric Wong [Tue, 21 Sep 2021 07:41:55 +0000 (07:41 +0000)]
lei: various completion improvements

"lei export-kw" no longer completes for anonymous sources.

More commands use "lei refresh-mail-sync" as a basis for their
completion work, as well.

";AUTH=ANONYMOUS@" is stripped from completions since it was
preventing bash completion from working on AUTH=ANONYMOUS IMAP
URLs.  I'm not sure if there's a better way, but all of our code
works fine without specifying AUTH=ANONYMOUS as a command-line
arg.

Finally, we fallback to using more candidates if none can
be found, allowing multiple URLs to be completed.

2 years agolei lcat: support NNTP URLs
Eric Wong [Tue, 21 Sep 2021 07:41:54 +0000 (07:41 +0000)]
lei lcat: support NNTP URLs

NNTP URLs are probably more prevalent in public message archives
than IMAP URLs.

2 years agodoc: lei-security: section for WIP auth methods
Eric Wong [Tue, 21 Sep 2021 07:41:53 +0000 (07:41 +0000)]
doc: lei-security: section for WIP auth methods

Lots of stuff out there that becomes a pain to setup
configuration for and test...

2 years agolei lcat: use single queue for ordering
Eric Wong [Tue, 21 Sep 2021 07:41:52 +0000 (07:41 +0000)]
lei lcat: use single queue for ordering

If lcat-ing multiple argument types (blobs vs folders),
maintain the original order of the arguments instead of
dumping all blobs before folder contents.

2 years agolei: simplify internal arg2folder usage
Eric Wong [Tue, 21 Sep 2021 07:41:51 +0000 (07:41 +0000)]
lei: simplify internal arg2folder usage

We can set opt->{quiet} for (internal) 'note-event' command
to quiet ->qerr, since we use ->qerr everywhere else.  And
we'll just die() instead of setting a ->{fail} message, since
eval + die are more inline with the rest of our Perl code.

2 years agolei_mail_sync: account for non-unique cases
Eric Wong [Tue, 21 Sep 2021 07:41:50 +0000 (07:41 +0000)]
lei_mail_sync: account for non-unique cases

NNTP servers, IMAP servers, and various MUAs may recycle
"unique" identifiers due to software bugs or careless BOFHs.
Warn about them, but always be prepared to account for them.

2 years agolei inspect: support NNTP URLs
Eric Wong [Tue, 21 Sep 2021 07:41:49 +0000 (07:41 +0000)]
lei inspect: support NNTP URLs

No reason not to support them, since there's more
public-inbox-nntpd instances than -imapd instances,
currently.

2 years agolei inspect: convert to WQ worker
Eric Wong [Tue, 21 Sep 2021 07:41:48 +0000 (07:41 +0000)]
lei inspect: convert to WQ worker

Xapian and SQLite access can be slow when a DB is large and/or
on high-latency storage.

2 years agogcf2: fix loading at runtime
Eric Wong [Mon, 20 Sep 2021 13:00:33 +0000 (13:00 +0000)]
gcf2: fix loading at runtime

We need to waitpid synchronously on pkg-config to use $?.

When loading Gcf2 inside the event loop, implicit dwaitpid
done by PublicInbox::ProcessPipe would not call waitpid in
time to zero $?.  This was causing one of my -httpd to
occasionally fall back to git(1) instead of using Gcf2.

This was noted in:
Link: https://public-inbox.org/meta/20210914085322.25517-1-e@80x24.org/
2 years agonet_reader: NNTP: remove article numbers from mail_sync folders
Eric Wong [Sun, 19 Sep 2021 22:51:57 +0000 (17:51 -0500)]
net_reader: NNTP: remove article numbers from mail_sync folders

NNTP article numbers are stored separately from folder names
in mail_sync.sqlite3.

Recovering from this is optional, worse case is wasting
bandwidth refetching some messages.  To (optionally) recover
from this, use:

lei forget-mail-sync $URL_WITH_ARTNUMS

Some articles will be refetched on the next import, but
duplicate data won't be indexed in Xapian.

2 years agodoc: lei-config: document various knobs
Eric Wong [Sun, 19 Sep 2021 12:50:35 +0000 (12:50 +0000)]
doc: lei-config: document various knobs

It's still a work-in-progress, but the basic debug knob
comes in handy for new users; as does proxy support.

2 years agonet_reader: disallow imap.fetchBatchSize=0
Eric Wong [Sun, 19 Sep 2021 12:50:34 +0000 (12:50 +0000)]
net_reader: disallow imap.fetchBatchSize=0

A batch size of zero is nonsensical and causes infinite loops.

2 years agolei config --edit: use controlling terminal
Eric Wong [Sun, 19 Sep 2021 12:50:33 +0000 (12:50 +0000)]
lei config --edit: use controlling terminal

As with "lei edit-search", "lei config --edit" may
spawn an interactive editor which works best from
the terminal running script/lei.

So implement LeiConfig as a superclass of LeiEditSearch
so the two commands can share the same verification
hooks and retry logic.

2 years agonet_reader: no STARTTLS for IMAP localhost or onions
Eric Wong [Sun, 19 Sep 2021 12:50:32 +0000 (12:50 +0000)]
net_reader: no STARTTLS for IMAP localhost or onions

At least not by default, to match existing NNTP behavior.
Tor .onions are already encrypted, and there's no point
in encrypting traffic on localhost outside of testing.

2 years agowatch: use net_reader->mic_new wrapper for SOCKS+TLS
Eric Wong [Sun, 19 Sep 2021 12:50:31 +0000 (12:50 +0000)]
watch: use net_reader->mic_new wrapper for SOCKS+TLS

This brings -watch up to feature parity with lei with
SOCKS support.

2 years agoxt: add fsck script over over.sqlite3
Eric Wong [Sun, 19 Sep 2021 12:50:30 +0000 (12:50 +0000)]
xt: add fsck script over over.sqlite3

I'm not sure what caused it, but I've noticed two missing
messages that failed from "lei up" on an https:// external;
and I've also seen some duplicates in the past (which I
think I fixed...).

2 years agonet_reader: fix single NNTP article fetch, test ranges
Eric Wong [Sun, 19 Sep 2021 12:50:29 +0000 (12:50 +0000)]
net_reader: fix single NNTP article fetch, test ranges

While NNTP ranges was already working, fetching a single message
was broken.  We'll also simplify the code a bit and ensure
incremental synchronization is ignored when ranges are
specified.

2 years agolei ls-mail-source: pretty JSON support
Eric Wong [Sun, 19 Sep 2021 12:50:28 +0000 (12:50 +0000)]
lei ls-mail-source: pretty JSON support

As with other commands, we enable pretty JSON by default if
stdout is a terminal or if --pretty is specified.  While the
->pretty JSON output has excessive vertical whitespace, too many
lines is preferable to having everything on one line.

2 years agolei ls-mail-source: use "high"/"low" for NNTP
Eric Wong [Sun, 19 Sep 2021 12:50:27 +0000 (12:50 +0000)]
lei ls-mail-source: use "high"/"low" for NNTP

The meanings of "hwm" and "lwm" may not be obvious abbreviations
for (high|low) water mark descriptions used by RFC 3977.
"high" and "low" should be obvious to anyone.

2 years agolei: clamp internal worker processes to 4
Eric Wong [Sun, 19 Sep 2021 12:50:26 +0000 (12:50 +0000)]
lei: clamp internal worker processes to 4

"All" my CPUs is only 4, but it's probably ridiculous for
somebody with a 16-core system to have 16 processes for
accessing SQLite DBs.

We do the same thing in Pmdir for parallel Maildir access
(and V2Writable).

2 years agoipc: drop dynamic WQ process counts
Eric Wong [Sun, 19 Sep 2021 12:50:25 +0000 (12:50 +0000)]
ipc: drop dynamic WQ process counts

In retrospect, I don't think it's needed; and trying to wire up
a user interface for lei to manage process counts doesn't seem
worthwhile.  It could be resurrected for public-facing daemon
use in the future, but that's what version control systems are for.

This also lets us automatically avoid setting up broadcast
sockets

Followup-to: 7b7939d47b336fb7 ("lei: lock worker counts")
2 years agolei_xsearch: drop Data::Dumper use
Eric Wong [Sun, 19 Sep 2021 12:50:24 +0000 (12:50 +0000)]
lei_xsearch: drop Data::Dumper use

We're not using Data::Dumper for JSON output.

2 years agolei: simplify sto_done_request
Eric Wong [Sun, 19 Sep 2021 12:50:23 +0000 (12:50 +0000)]
lei: simplify sto_done_request

With the switch from pipes to sockets for lei-daemon =>
lei/store IPC, we can send the script/lei client socket to the
lei/store process and rely on reference counting in both Perl
and the kernel to persist the script/lei.

2 years agolei/store: use SOCK_SEQPACKET rather than pipe
Eric Wong [Sun, 19 Sep 2021 12:50:22 +0000 (12:50 +0000)]
lei/store: use SOCK_SEQPACKET rather than pipe

This has several advantages:

* no need to use ipc.lock to protect a pipe for non-atomic writes

* ability to pass FDs.  In another commit, this will let us
  simplify lei->sto_done_request and pass newly-created
  sockets to lei/store directly.

disadvantages:

- an extra pipe is required for rare messages over several
  hundred KB, this is probably a non-issue, though

The performance delta is unknown, but I expect shards
(which remain pipes) to be the primary bottleneck IPC-wise
for lei/store.

2 years agoipc: allow disabling broadcast for wq_workers
Eric Wong [Sun, 19 Sep 2021 12:50:21 +0000 (12:50 +0000)]
ipc: allow disabling broadcast for wq_workers

Since some lei worker classes only use a single worker,
there's no sense in having broadcast for those cases.

2 years agoipc: wq_do: support synchronous waits and responses
Eric Wong [Sun, 19 Sep 2021 12:50:20 +0000 (12:50 +0000)]
ipc: wq_do: support synchronous waits and responses

This brings the wq_* SOCK_SEQPACKET API functionality
on par with the ipc_do (pipe-based) API.

2 years agodoc: tuning: note git 2.33+, move libgit2 into Inline::C section
Eric Wong [Sun, 19 Sep 2021 00:36:04 +0000 (00:36 +0000)]
doc: tuning: note git 2.33+, move libgit2 into Inline::C section

git 2.33+ contains important optimizations for the
thousands-of-inboxes case.  And combine the Inline::C stuff
with libgit2, since our use of libgit2 requires Inline::C.

2 years agot/lei-refresh-mail-sync: improve test reliability
Eric Wong [Sat, 18 Sep 2021 22:38:43 +0000 (22:38 +0000)]
t/lei-refresh-mail-sync: improve test reliability

We can't assume -imapd will be ready by the time we try to
connect to it after restart when using "-l $ADDR".  So recreate
the (closed-for-testing) listen socket in the parent and hand it
off to -imapd as we do normally

2 years agonet_reader: quote URL properly for Tor .onion hint
Eric Wong [Sat, 18 Sep 2021 21:09:14 +0000 (21:09 +0000)]
net_reader: quote URL properly for Tor .onion hint

The semicolon in ';AUTH=ANONYMOUS' requires quoting in Bourne shell.

2 years agot/config: extra test for imap_url with imaps://
Eric Wong [Sat, 18 Sep 2021 20:33:24 +0000 (20:33 +0000)]
t/config: extra test for imap_url with imaps://

I configured this for public-inbox.org, but wasn't 100% sure it
worked.  This test ensures it stays working :>