Eric Wong [Wed, 29 Apr 2020 11:14:43 +0000 (11:14 +0000)]
t/precheck: remove Email::Simple->create from tests
It's likely we'll replace Email::Simple using our Email::MIME
alternative/replacement, as well. So reduce the API surface we
interact with and make it easier to swap implementations.
Eric Wong [Tue, 28 Apr 2020 08:48:58 +0000 (08:48 +0000)]
git: various minor speedups
While testing performance improvements elsewhere, I noticed some
micro-optimizations could give a small ~2-3% speedup in my test
using the git async API to parse a large inbox.
The `read' perlfunc already has read-in-full behavior (unless
git is killed unexpectedly), so there's no point in using a
loop. SearchIdxShard in the parallel v2 indexing code path
never looped on `read', either.
Furthermore, we can avoid method dispatch overhead on ->getline
and ->print by using `readline' and `print' as ops which can be
resolved during the Perl compilation phase.
Finally, avoid passing the IO handle around as a parameter,
since avoiding hash lookups with a local variable has its own
costs in stack and refcount bumping.
Eric Wong [Sat, 25 Apr 2020 05:52:22 +0000 (05:52 +0000)]
tests: remove Email::MIME->create use entirely
Replace them with .eml files generated with the help of
Email::MIME, but without some extraneous and unnecessary
headers, and strip mime_load down to just loading files.
This will give us more freedom to experiment with other mail
libraries which may be more correct, better maintained, use
less memory and/or be faster than Email::MIME.
Eric Wong [Sat, 25 Apr 2020 05:52:21 +0000 (05:52 +0000)]
testcommon: introduce mime_load sub
We'll use this to create, memoize, and reuse .eml files. This
will be used to reduce (and eventually eliminate) our dependency
on Email::MIME in tests.
Eric Wong [Tue, 21 Apr 2020 20:30:06 +0000 (20:30 +0000)]
doc: note some changes for 1.5
As an established project (:P), it's important to document when
new features appear in manpages. Users may be reading new
documentation online which doesn't reflect an older version they
have installed.
Eric Wong [Tue, 21 Apr 2020 21:16:12 +0000 (21:16 +0000)]
t/*.t: use Email::MIME->create over PublicInbox::MIME->create
PublicInbox::MIME only supports ->new, and is only different
from Email::MIME for old versions of Email::MIME. In the
future, PublicInbox::MIME may not be a subclass of Email::MIME
at all.
Eric Wong [Tue, 21 Apr 2020 06:57:34 +0000 (06:57 +0000)]
make zlib-related modules a hard dependency
This allows us to simplify some of our existing code and make
future changes easier.
I doubt anybody goes through the trouble to have a Perl
installation without zlib support. The zlib source code is even
bundled with Perl since 5.9.3 for systems without existing zlib
development headers and libraries.
Of course, zlib is also a requirement of git, too; and we're not
going to stop using git :)
In the second line, the omission character " is appended, but the
entire subject is shown. To display the subject with duplicated parts
omitted, regenerate it from the array that is modified by
dedupe_subject().
view: strip omission character from current message in thread view
In the thread view shown at the top of a message, the subject for the
current message is dropped, leaving just the sender's name. However,
if skel_dump() omitted part of the subject because it was duplicated,
the omission character is still displayed:
* [PATCH v2] t/www_listing: avoid 'once' warnings
2020-03-21 1:10 ` [PATCH 2/2] t/www_listing: avoid 'once' warnings Eric Wong
@ 2020-03-21 5:24 ` " Eric Wong
Note the " on the last line.
Adjust the regular expression in _th_index_lite() to account for the
omission character.
Eric Wong [Tue, 21 Apr 2020 03:22:51 +0000 (03:22 +0000)]
t/nntpd: reduce dependencies on internal API
Since the advent of run_script(), we can rely on it to simplify
our test code. Changes like this will let us evolve the
internal API more easily while preserving stable CLI interfaces,
especially since we test the v2 path by default, now.
Eric Wong [Mon, 20 Apr 2020 22:55:37 +0000 (22:55 +0000)]
index: support --max-size / publicinbox.indexMaxSize
In normal mail paths, we can rely on MTAs being configured with
reasonable limits in the -watch and -mda mail injection paths.
However, the MTA is bypassed in a git-only delivery path, a BOFH
could inject a large message and DoS users attempting to mirror
a public-inbox.
This doesn't protect unindexed WWW interfaces from Email::MIME
memory explosions on v1 inboxes. Probably nobody cares about
unindexed WWW interfaces anymore, especially now that Xapian is
optional for indexing.
Eric Wong [Fri, 17 Apr 2020 09:33:31 +0000 (09:33 +0000)]
qspawn: remove Perl 5.16.x leak workaround
It seems no longer necessary to workaround this Perl 5.16.3 bug
after the removal of anonymous subs from all of our internal
code in
https://public-inbox.org/meta/20191225075104.22184-1-e@80x24.org/
Tested with repeated clones (both aborted and completed)
in a CentOS 7.x VM which was once able to reproduce leaks
before the workaround appeared in 2fc42236f72ad16a
("qspawn: workaround Perl 5.16.3 leak, re-enable Deflater")
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Eric Wong [Mon, 20 Apr 2020 09:33:38 +0000 (09:33 +0000)]
drop needless `eval {}' around Config->new
It hasn't been needed since commit 089cca37fa036411
("config: ignore missing config files"). And we
actually want to propagate errors when we can't
start new processes or if git(1) is missing.
Eric Wong [Sun, 19 Apr 2020 23:19:35 +0000 (23:19 +0000)]
import: init_bare: use pure Perl
Even on systems with Inline::C spawn(), this cuts a primed
"make check-run" time by 2-3% on Linux, and roughly 5-7% on
FreeBSD when using vfork-enabled spawn.
I doubt anybody cares: this omits the sample hooks and some
empty and useless-for-us or obsolete directories created by
git-init(1).
The watchheader key supports only a single value. Supporting multiple
watchheader values was mentioned in discussion [1] of 8d3e3bd8 (doc:
explain publicinbox.<name>.watchheader, 2019-10-09), and it wasn't
clear if there was a need.
One scenario in which matching multiple headers would be convenient is
when someone wants to set up public-inbox archives for some small
projects but does _not_ want to run mailing lists for them, instead
allowing others to follow the project by any of the pull mechanisms.
Using a common underlying address, an address alias for each project
is configured via a third-party email provider, with messages for each
alias being exposed as a separate public-inbox archive. In this
setup, messages for an inbox cannot be selected by a List-ID header
but can be identified by the inbox's address in either the To or Cc
header.
To support such a use case, update the watchheader handling to
consider multiple values, accepting a message if it matches any value.
While selecting a message based on matching _any_ rather than _all_
values is motivated by the above scenario, it's worth noting that the
"any" behavior is consistent with how multiple listid config values
are handled.
Eric Wong [Fri, 17 Apr 2020 10:24:45 +0000 (10:24 +0000)]
doc: start writeup on semi-automatic memory management
I don't consider Perl's memory management "automatic". Instead,
having an extra bit of control as a hacker is nice and there's
no need to burden ordinary users with GC tuning knobs.
Eric Wong [Sat, 18 Apr 2020 03:38:53 +0000 (03:38 +0000)]
reduce scope of mbox From_ line removal
It's unnecessary overhead for anything which does Email::MIME
parsing. It was never done for v2 indexing, even though v1->v2
conversions did NOT remove those From_ lines. There was never a
need to remote From_ lines the v1 SearchIdx paths, either.
Hitting a /$INBOX_URL/$MSGID/T/ endpoint with an 18 message
thread reveals a ~0.5% speed improvement. This will become
more apparent when we have a faster MIME parser.
Eric Wong [Sat, 18 Apr 2020 03:38:50 +0000 (03:38 +0000)]
favor `do {}' over `eval {}' for localized slurp
I did not know to use the return value of `do' back in the day.
There's probably no practical difference in these cases, but
`eval' is overkill for these uses and may hide actual errors.
We can get rid of a few redundant `scalar' ops and pass scalar
refs to Email::MIME->new to avoid copies in a few more places,
too.
Eric Wong [Sat, 18 Apr 2020 03:38:47 +0000 (03:38 +0000)]
searchidx: die on cat-file failures
We always use the object ID from "git <log|rev-list>" for
retrieving blobs, so fail loudly if the git repository is
corrupt instead of silently continuing.
Eric Wong [Sat, 18 Apr 2020 03:38:46 +0000 (03:38 +0000)]
inboxwritable: mime_from_path: reuse in more places
There's nothing Maildir-specific about the function, so
`maildir_path_load' was a bad name. So give it a more
appropriate name and use it in our tests.
This save ourselves some code and inconsistency by reusing an
existing internal library routine in more places. We can drop
the "From_" line in some of our (formerly) mbox sample files.
Eric Wong [Fri, 17 Apr 2020 09:28:49 +0000 (09:28 +0000)]
searchthread: reduce indirection by removing container
We can rid ourselves of a layer of indirection by subclassing
PublicInbox::Smsg instead of using a container object to hold
each $smsg. Furthermore, the `{id}' vs. `{mid}' field name
confusion is eliminated.
This reduces the size of the $rootset passed to walk_thread by
around 15%, that is over 50K memory when rendering a /$INBOX/
landing page.
Eric Wong [Thu, 16 Apr 2020 00:29:38 +0000 (00:29 +0000)]
t/httpd-corner: improve reliability and diagnostics
The graceful-shutdown-on-PUT test is unreliable because we can't
rely on a FIFO as we do with the GET tests. So increase the
delay to 100ms since that seems enough on my system even with
CONFIG_HZ=100.
Add a timeout and backtrace to the $check_self sub to help with
further diagnostics while we're at it, too.
It would be nice if there were a portable syscall tracing
mechanism we could attach to the -httpd process to make the test
more determistic...
I've observed FreeBSD 11.2 read(2) having one of three
behaviors after a failed write(2) on a socket:
1) returning number of bytes read
2) failing with ECONNRESET
3) returning with EOF
1) is the most common, and I've only seen 1) on Linux. It may
be possible to use SO_LINGER or shutdown(2) to ensure 1) always
happens, but SO_LINGER behavior seems inconsistent across OSes,
especially with non-blocking sockets.
Since these tests are corner-cases where we're dealing with
broken/malicious clients, lets continue spending the least
amount of syscalls protecting ourselves in the daemon and
instead make the client-side test code tolerate more socket
implementations.
Eric Wong [Sat, 11 Apr 2020 10:53:28 +0000 (10:53 +0000)]
dskqxs: ignore EV_SET errors on EVFILT_WRITE
Just like the EPOLL_CTL_ADD emulation path, the EPOLL_CTL_MOD
and EPOLL_CTL_DEL emulation paths can fail if attempting to
install an EVFILT_WRITE for a read-only pipe.
I've only observed this on the EPOLL_CTL_DEL emulation path, but
I suspect it could happen on the EPOLL_CTL_MOD path as well.
Increasing the amount of read-only pipes we rely on with altid
exports via sqlite3 made this old bug more apparent and
reproducible while looping the test suite.
This may be adjusted in the future to deal with write-only
pipes, but we currently don't have any of those watched by
kqueue.
Eric Wong [Tue, 7 Apr 2020 09:35:14 +0000 (04:35 -0500)]
doc: add technical/whyperl
Some people don't like Perl; but it exists, there's no
avoiding it with everything that depends on it. And
nearly all code still works unmodified after 20 years.
Eric Wong [Tue, 7 Apr 2020 21:55:53 +0000 (21:55 +0000)]
tests: document run_mode=1 as not implemented
It was implemented at some point, but it was more things to
support and the worst of both worlds: both unrealistic compared
to real-world use and slower than run_mode=2.
Eric Wong [Mon, 6 Apr 2020 08:32:52 +0000 (08:32 +0000)]
view: do not redundantly obfuscate addresses
We shouldn't rerun the address obfuscator on data we've
already run through. Instead, run through the unescaped
text part and substitute the UTF-8 "\x{2022}" substitution
before it hits HTML escaping
Eric Wong [Mon, 6 Apr 2020 20:23:01 +0000 (20:23 +0000)]
portability: constants for NetBSD
NetBSD implements O_CLOEXEC, so let us use it to avoid
inadvertant FD sharing. It also has the same value for SIGWINCH
as Linux and the other BSDs we support.
Eric Wong [Sun, 5 Apr 2020 07:53:49 +0000 (07:53 +0000)]
git: reduce stat buffer storage overhead
The stat() array is a whopping 480 bytes (on x86-64, Perl 5.28),
while the new packed representation of two 64-bit doubles as a
scalar is "only" 56 bytes. This can add up when there's many
inboxes. Just use a string comparison on the packed
representation.
Some 32-bit Perl builds (IIRC OpenBSD) lack quad support, so
doubles were chosen for pack() portability.
Eric Wong [Sun, 5 Apr 2020 07:53:48 +0000 (07:53 +0000)]
mbox: halve ->getline "context switches"
We don't need to take extra trips through the event loop for a
single message (in the common case of Message-IDs being unique).
In fact, holding the body reference left behind by Email::Simple
could be harmful to memory usage, though in practice it's not a
big problem since code paths which use Email::MIME take far more.
Eric Wong [Sun, 5 Apr 2020 07:53:47 +0000 (07:53 +0000)]
release large (non ref) scalars using `undef $sv'
Using `undef EXPR' like a function call actually frees the heap
memory associated with the scalar, whereas `$sv = undef' or
`$sv = ""' will hold the buffer around until $sv goes out
of scope.
The `sv_set_undef' documentation in the perlapi(1) manpage
explicitly states this:
The perl equivalent is "$sv = undef;". Note that it doesn't
free any string buffer, unlike "undef $sv".
And I've confirmed by reading Dump() output from Devel::Peek.
We'll also inline the old index_body sub in SearchIdx.pm to make
the scope of the scalar more obvious.
This change saves several hundred kB RSS on both -index and
-httpd when hitting large emails with thousands of lines.
Eric Wong [Sat, 4 Apr 2020 23:51:41 +0000 (23:51 +0000)]
xt/msgtime_cmp: fix false positives from msgtime change
commit d857e7dc0d816b635a7ead09c3273f8c2d2434be
("msgtime: assume +0000 if TZ missing when using Date::Parse")
introduced a behavior change which was causes false positives
when compared to the old code.
Update the "old" implementation to match this overdue behavior
change.
Eric Wong [Sun, 5 Apr 2020 01:28:49 +0000 (01:28 +0000)]
wwwstatic: set "Vary: Accept-Encoding" in static gzip response
We don't want to confuse intermediate caches into serving
gzipped content to any clients which can't handle it. It
probably doesn't matter in practice, though, since every HTTP
client seems to handle "Content-Encoding: gzip" regardless of
whether it was requested or not, though I could expect some
nc/socat/telnet/s_client users being annoyed.
This also matches the behavior of Plack::Middleware::Deflater
and other deflater implementations.
Eric Wong [Sat, 4 Apr 2020 08:03:18 +0000 (08:03 +0000)]
viewdiff: reduce sub parameter count
We're slowly moving towards doing all of our output buffering
into a single buffer, so passing that around on the stack as
a dedicated parameter is confusing.
Eric Wong [Sat, 4 Apr 2020 08:03:17 +0000 (08:03 +0000)]
view: dedupe_subject: allow "0" as a valid Subject
While rare in practice (even by spammers), A single "0" could
theoretically be the entire contents of a Subject line. So
use the Perl 5.10+ defined-or operator to improve correctness
of subject deduplication.
These seem mostly harmless since Perl will just truncate the
match and start a new one on a newline boundary in our case.
The only downside is we'd end up with redundant <span> tags in
HTML.
Limiting the number of line matched ourselves with `{1,$NUM}'
doesn't seem prudent since lines vary in length, so we continue
to defer the job of limiting matches to the Perl regexp engine.
I've noticed this warning in practice on 100K+ line patches to
locale data.
Eric Wong [Wed, 1 Apr 2020 06:16:20 +0000 (06:16 +0000)]
mid: add $MID_EXTRACT regexp for export
This allows us to consistently enforce the same Message-ID
extraction rules everywhere and makes it easier for us to
make changes in the future.
Update scripts/ssoma-replay, as well, but don't rely on
PublicInbox::* modules in that since it's legacy and
public-inbox was never a dependency of ssoma.
Eric Wong [Wed, 1 Apr 2020 06:16:18 +0000 (06:16 +0000)]
smsg: inline _extract_mid functionality
No need to keep an extra sub which isn't called anywhere else,
and the mid_clean call is redundant since mid_mime already
plucks the msgid out of the angle brackets.
Eric Wong [Tue, 31 Mar 2020 08:49:36 +0000 (08:49 +0000)]
v2writable: index Message-IDs w/ spaces properly
Message-IDs can apparently contain spaces and other weird
characters. Ensure we pass those properly to shard subprocesses
when importing messages in parallel mode.
Our NNTP request parser does not deal with spaces in the
Message-ID, yet, and I don't expect most NNTP clients to,
either. Nor does the Net::NNTP client handle them in responses.
Eric Wong [Mon, 30 Mar 2020 19:42:54 +0000 (19:42 +0000)]
t/multi-mid: allow test to run w/o Xapian
While the v1 inbox in this test is created without Xapian,
the v2 inbox in this test defaults to having Xapian enabled
regardless of whether it's installed or not.
Fixes: c7acdfe78bda5bf3 ("v2: SDBM-based multi Message-ID queue")
git-cat-file(1) may return less than the $BIN_DETECT value for
some blobs, so ensure we repopulate the values in $ctx for
retries in that case, otherwise we'll lose `$ctx->{-res}' and
die when attempting to use `undef' as an array ref.
Eric Wong [Mon, 30 Mar 2020 05:18:42 +0000 (00:18 -0500)]
wwwstream::oneshot => html_oneshot
And use Exporter to make our life easier, since WwwAltId was
using a non-existent PublicInbox::WwwResponse namespace in error
paths which doesn't get noticed by `perl -c' or exercised by
tests on normal systems.
Fixes: 6512b1245ebc6fe3 ("www: add endpoint to retrieve altid dumps")
Eric Wong [Sat, 28 Mar 2020 00:56:04 +0000 (00:56 +0000)]
index: support --compact / -c on command-line
It's more convenient to specify `-c' / `--compact' on the
command-line when reindexing than it is to invoke
public-inbox-compact(1) separately.
This is especially convenient in low-space situations when
public-inbox-index is operating on multiple inboxes
sequentially, as compaction can happen immediately after
indexing each inbox, instead of waiting until all inboxes are
indexed.
Eric Wong [Sat, 28 Mar 2020 00:56:03 +0000 (00:56 +0000)]
searchidxshard: ensure we set indexlevel on shard[0]
For sharded v2 repositories with few-enough messages, it is
possible for shard[0] to go unused and never trigger the
->commit_txn_lazy to set the indexlevel field in Xapian
metadata.
So set it immediately at initialization and avoid this case.
While we're at it, avoid triggering needless pwrite syscalls
from ->set_metadata by checking with ->get_metadata, first.
Eric Wong [Thu, 26 Mar 2020 08:21:29 +0000 (08:21 +0000)]
wwwaltid: inform users to use POST instead of GET
Seeing the example config linkified, some users may inevitably
try to following it in a browser with a GET request. Provide
a helpful message to inform users to use POST instead of
attempting to treat /$INBOX/$ALTID.sql.gz as a Message-Id.