]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
4 years agopublic-inbox 1.4.0 v1.4.0
Eric Wong [Fri, 17 Apr 2020 08:41:23 +0000 (08:41 +0000)]
public-inbox 1.4.0

4 years agot/httpd-unix: skip some tests w/o signalfd|EVFILT_SIGNAL
Eric Wong [Fri, 17 Apr 2020 05:22:54 +0000 (05:22 +0000)]
t/httpd-unix: skip some tests w/o signalfd|EVFILT_SIGNAL

Some of these tests just don't seem reliable enough with the
way we or Perl do portable signal handling.

4 years agot/httpd-corner: improve reliability and diagnostics
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...

4 years agot/httpd-corner.t: relax read-after-failed-write handling
Eric Wong [Sat, 11 Apr 2020 10:53:30 +0000 (10:53 +0000)]
t/httpd-corner.t: relax read-after-failed-write handling

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.

4 years agot/*.t: localize $SIG{__WARN__} changes
Eric Wong [Sat, 11 Apr 2020 10:53:29 +0000 (10:53 +0000)]
t/*.t: localize $SIG{__WARN__} changes

We don't want to propagate %SIG changes to other tests when
running multiple tests within the same process via t/run.perl.

4 years agodskqxs: ignore EV_SET errors on EVFILT_WRITE
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.

4 years agotestcommon: DESTROY: wait for killed daemon
Eric Wong [Sat, 11 Apr 2020 10:53:27 +0000 (10:53 +0000)]
testcommon: DESTROY: wait for killed daemon

Otherwise, the waitpid(-1, 0) call in Xapcmd::process_queue()
may reap it in a subsequent test when using t/run.perl to reuse
processes for testing.

While we're at it, make Xapcmd::process_queue warn about unknown
PIDs in case other PIDs leak through to us in the future.

4 years agoMANIFEST update
Eric Wong [Wed, 15 Apr 2020 10:15:56 +0000 (10:15 +0000)]
MANIFEST update

4 years agodoc: add technical/whyperl
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.

4 years agodoc: start reproducibility document
Eric Wong [Tue, 7 Apr 2020 08:01:36 +0000 (08:01 +0000)]
doc: start reproducibility document

Not new ideas, just gathering thoughts.

4 years agodoc: escape internal ">" in listid code snippet
Kyle Meyer [Sat, 11 Apr 2020 21:05:01 +0000 (17:05 -0400)]
doc: escape internal ">" in listid code snippet

A code snippet in the listid description is incorrectly rendered as

    "publicinbox.$NAME.watchheader=List-Id:<foo.example.com">

Escape the closing bracket around the List-Id value to avoid this.
Also escape the opening bracket for symmetry/readability.

4 years agot/httpd-unix: improve test reliability
Eric Wong [Tue, 7 Apr 2020 21:02:30 +0000 (21:02 +0000)]
t/httpd-unix: improve test reliability

Net::Server::Daemonize::create_pid_file does not
write the PID file atomically, so we need to barf
if it's incomplete.

4 years agotriewyde: ficks soem speling errrors
Eric Wong [Tue, 7 Apr 2020 21:55:54 +0000 (21:55 +0000)]
triewyde: ficks soem speling errrors

Dikshunarees R gude!

4 years agotests: document run_mode=1 as not implemented
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.

Noticed while looking for speling erorrs.

4 years agoview: do not redundantly obfuscate addresses
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

Fixes: 9bdd81dc16ba6511 ("view: msg_iter calls add_body_text directly")
4 years agoportability: constants for NetBSD
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.

4 years agoxt/perf-msgview: update to use git->cat_async
Eric Wong [Mon, 6 Apr 2020 23:16:27 +0000 (23:16 +0000)]
xt/perf-msgview: update to use git->cat_async

It's about 5-10% faster on an SMP machine with an SSD,
even on a hot Linux page cache.

4 years agoexamples/grok-pull.post_update_hook: move url_base to the top
Eric Wong [Mon, 6 Apr 2020 09:56:21 +0000 (09:56 +0000)]
examples/grok-pull.post_update_hook: move url_base to the top

Users are encouraged to edit this script, anyways, so make it
easy for them to swap out and use whatever URL they need.

4 years agoexamples/grok-pull.post_update_hook: capture infourl
Eric Wong [Mon, 6 Apr 2020 09:56:20 +0000 (09:56 +0000)]
examples/grok-pull.post_update_hook: capture infourl

The value of infourl parameters are shared in the config, so
include them in the mirror.

4 years agoexamples/grok-pull.post_update_hook: fetch mirror description
Eric Wong [Mon, 6 Apr 2020 09:56:19 +0000 (09:56 +0000)]
examples/grok-pull.post_update_hook: fetch mirror description

The $INBOX_URL/description endpoint is available since v1.3.0,
so use it in mirrors.

4 years agogit: reduce stat buffer storage overhead
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.

4 years agombox: halve ->getline "context switches"
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.

4 years agorelease large (non ref) scalars using `undef $sv'
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.

4 years agoxt/msgtime_cmp: fix false positives from msgtime change
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.

4 years agowwwstatic: set "Vary: Accept-Encoding" in static gzip response
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.

4 years agoview: inline flush_quote sub
Eric Wong [Sat, 4 Apr 2020 08:03:19 +0000 (08:03 +0000)]
view: inline flush_quote sub

No point in having an extra sub for a short, commonly
called function in the same file.

4 years agoviewdiff: reduce sub parameter count
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.

4 years agoview: dedupe_subject: allow "0" as a valid Subject
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.

4 years agoview: use defined-or operator to simplify checks
Eric Wong [Sat, 4 Apr 2020 08:03:16 +0000 (08:03 +0000)]
view: use defined-or operator to simplify checks

We depend on Perl 5.10 features in other places.  Shorten the
lifetime of the `$desc' scalar while we're at it.

4 years agoview: note we assume UTF-8 on unknown encodings
Eric Wong [Sat, 4 Apr 2020 08:03:15 +0000 (08:03 +0000)]
view: note we assume UTF-8 on unknown encodings

Clarify that we're assuming the text is UTF-8, since users
may have no idea how it's mangled.

4 years agoinboxwritable: fix From_ line unescaping
Eric Wong [Sat, 4 Apr 2020 06:17:29 +0000 (06:17 +0000)]
inboxwritable: fix From_ line unescaping

We can't rely on Email::MIME noticing the change to our
scalar ref after calling `PublicInbox::MIME->new'.

This is because Email::MIME::body_set (unlike
Email::Simple::body_set) will copy the contents of the body into
`->{body_raw}' as a new scalar.

Furthermore, we need to escape multiple From lines in the body,
not just the first one, using the `g' modifier to `s//'.

Reported-by: Kyle Meyer <kyle@kyleam.com>
4 years agoquiet "Complex regular subexpression recursion limit" warnings
Eric Wong [Fri, 3 Apr 2020 21:06:20 +0000 (21:06 +0000)]
quiet "Complex regular subexpression recursion limit" warnings

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.

4 years agoview: handle the topic-free case properly
Eric Wong [Fri, 3 Apr 2020 05:06:59 +0000 (05:06 +0000)]
view: handle the topic-free case properly

There may be no topics for a given timestamp range,
so don't attempt to treat `undef' as an arrayref.

4 years agonntp: allow multiple spaces or tabs to delimit args
Eric Wong [Thu, 2 Apr 2020 00:17:13 +0000 (00:17 +0000)]
nntp: allow multiple spaces or tabs to delimit args

While this is not a known problem in practice,
RFC 3977 section 3.1 states:

Keywords and arguments MUST each be separated by one
or more space or TAB characters.

4 years agomid: add $MID_EXTRACT regexp for export
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.

4 years agosearchidx: v1: skip mid_clean on mid_mime results
Eric Wong [Wed, 1 Apr 2020 06:16:19 +0000 (06:16 +0000)]
searchidx: v1: skip mid_clean on mid_mime results

We do not need run mid_clean() since mid_mime() uses mids()
to extract the msgid from inside the angle brackets.

4 years agosmsg: inline _extract_mid functionality
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.

4 years agoREADME: add a missing "be"
Kyle Meyer [Thu, 2 Apr 2020 00:26:14 +0000 (00:26 +0000)]
README: add a missing "be"

4 years agoREADME: expand on the GUI non-requirement
Eric Wong [Wed, 1 Apr 2020 06:04:40 +0000 (01:04 -0500)]
README: expand on the GUI non-requirement

It may not be immediately obvious why we should value text-based
stuff so much, so clarify that.

4 years agodoc: update notes and HACKING ahead of 1.4 release
Eric Wong [Wed, 1 Apr 2020 06:04:41 +0000 (01:04 -0500)]
doc: update notes and HACKING ahead of 1.4 release

There will probably be a 1.4 release in a few days...

4 years agov2writable: index Message-IDs w/ spaces properly
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.

4 years agot/multi-mid: allow test to run w/o Xapian
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")
4 years agoviewvcs: stream_blob_parse_hdr: fix BIN_DETECT retries
Eric Wong [Mon, 30 Mar 2020 18:30:09 +0000 (18:30 +0000)]
viewvcs: stream_blob_parse_hdr: fix BIN_DETECT retries

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.

4 years agoqspawn: capture errors from parse_hdr callback
Eric Wong [Mon, 30 Mar 2020 18:30:08 +0000 (18:30 +0000)]
qspawn: capture errors from parse_hdr callback

User-supplied callbacks may fail, so capture the error instead
of propagating it up the stack into the public-inbox-httpd event
loop.

4 years agowwwstream::oneshot => html_oneshot
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")
4 years agot/filter_rubylang.t: avoid warning for non-word prefix
Eric Wong [Sun, 29 Mar 2020 19:32:31 +0000 (19:32 +0000)]
t/filter_rubylang.t: avoid warning for non-word prefix

The "-" was never supported by Xapian in the prefix, but
it could still be used to make documentation and URLs more
readable in certain cases.

Fixes: 7909c5f7439777e3 ("altid: warn about non-word prefixes")
4 years agoindex: support --compact / -c on command-line
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.

4 years agosearchidxshard: ensure we set indexlevel on shard[0]
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.

4 years agoconfig: Honor gitconfig includes
Andreas Rottmann [Sun, 29 Mar 2020 11:12:50 +0000 (13:12 +0200)]
config: Honor gitconfig includes

This allows for a setup where a central config file for the web server
includes per-user config files.

4 years agowwwaltid: inform users to use POST instead of GET
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.

4 years agowwwtext: show altid instructions in config
Eric Wong [Thu, 26 Mar 2020 08:21:28 +0000 (08:21 +0000)]
wwwtext: show altid instructions in config

Exposing altid dumps will help and ensure total reproducibility
of existing instances.

AFAIK, sqlite3(1) can't execute arbitrary code, so it's not
quite as fashionable as the "curl | bash" stuff the cool people
are doing, these days :P

4 years agoinbox: altid_map becomes a method
Eric Wong [Thu, 26 Mar 2020 08:21:27 +0000 (08:21 +0000)]
inbox: altid_map becomes a method

We want to be able to preload that, as well as to access it
in WwwText for a config comment in the config example.

4 years agowww: add endpoint to retrieve altid dumps
Eric Wong [Sat, 21 Mar 2020 02:03:54 +0000 (02:03 +0000)]
www: add endpoint to retrieve altid dumps

This ensures all our indexed data, including data from altid
searches (e.g. "gmane:$ARTNUM") is retrievable.

It uses a "POST" request to avoid wasting cycles when invoked by
crawlers, since it could potentially be several megabytes of
data not indexable by search engines.

4 years agoaltid: warn about non-word prefixes
Eric Wong [Sat, 21 Mar 2020 02:03:53 +0000 (02:03 +0000)]
altid: warn about non-word prefixes

We only support searching on prefixes matching /\A\w+\z/ because
Xapian requires ':' to delimit the prefix and splits on spaces
without quotes.

I've also verified Xapian supports multibyte UTF-8 characters,
underscores, and bare numbers as search prefixes, so there's
no need to restrict it beyond what Perl's UTF-8 aware \w
character class offers.

4 years agowwwtext: show thread endpoint w/ indexlevel=basic
Eric Wong [Sat, 21 Mar 2020 02:03:52 +0000 (02:03 +0000)]
wwwtext: show thread endpoint w/ indexlevel=basic

And show contact info when there's no indexing, at all.
Installations where Xapian is too expensive can still support
threading since it only depends on SQLite, so we need to inform
users of what's available.

4 years agosearch: clobber -user_pfx on query parser initialization
Eric Wong [Sat, 21 Mar 2020 02:03:51 +0000 (02:03 +0000)]
search: clobber -user_pfx on query parser initialization

While we don't currently reinitialize the query parser for
the lifetime of a PublicInbox::Search object and have no plans
to, it's incorrect to be appending to an existing array in
case we reininitialize the query parser in the future.

4 years agoqspawn: handle ENOENT (and other errors on exec)
Eric Wong [Sat, 21 Mar 2020 02:03:50 +0000 (02:03 +0000)]
qspawn: handle ENOENT (and other errors on exec)

As sqlite3(1) and other executables may become unavailable or
uninstalled while a daemon runs, we need to gracefully handle
errors in those cases.

4 years agombox: need_gzip uses WwwStream::oneshot
Eric Wong [Sat, 21 Mar 2020 02:03:49 +0000 (02:03 +0000)]
mbox: need_gzip uses WwwStream::oneshot

This makes the error page more consistent.

Not that it really matters since Compress::Raw::Zlib and
IO::Compress packages have been distributed with Perl since
5.10.x.  Of course, zlib itself is also a dependency of git.

4 years agowwwstream: oneshot sets content-length
Eric Wong [Sat, 21 Mar 2020 02:03:48 +0000 (02:03 +0000)]
wwwstream: oneshot sets content-length

PublicInbox::HTTP will chunk, otherwise, and that's
extra overhead which isn't needed.

4 years agoextmsg: use WwwResponse::oneshot
Eric Wong [Sat, 21 Mar 2020 02:03:47 +0000 (02:03 +0000)]
extmsg: use WwwResponse::oneshot

No reason to use the ->getline interface for small responses.

4 years agowwwstream: introduce oneshot API to avoid ->getline
Eric Wong [Sat, 21 Mar 2020 02:03:46 +0000 (02:03 +0000)]
wwwstream: introduce oneshot API to avoid ->getline

The ->getline API is only useful for limiting memory use when
streaming responses containing multiple emails or log messages.
However it's unnecessary complexity and overhead for callers
(PublicInbox::HTTP) when there's only a single message.

4 years agogzipfilter: lazy allocate the deflate context
Eric Wong [Sat, 21 Mar 2020 02:03:45 +0000 (02:03 +0000)]
gzipfilter: lazy allocate the deflate context

zlib contexts are memory-intensive, particularly when used for
compression.  Since the gzip filter may be sitting in a limiter
queue for a long period, delay the allocation we actually have
data to translate, and not a moment sooner.

4 years agoqspawn: reinstate filter support, add gzip filter
Eric Wong [Sat, 21 Mar 2020 02:03:44 +0000 (02:03 +0000)]
qspawn: reinstate filter support, add gzip filter

We'll be supporting gzipped from sqlite3(1) dumps
for altid files in future commits.

In the future (and if we survive), we may replace
Plack::Middleware::Deflater with our own GzipFilter to work
better with asynchronous responses without relying on
memory-intensive anonymous subs.

4 years agodaemon: unlink .oldbin PID file correctly
Eric Wong [Sun, 22 Mar 2020 08:58:49 +0000 (08:58 +0000)]
daemon: unlink .oldbin PID file correctly

We need to track the PID file having ".oldbin" appended
to it while a SIGUSR2 upgrade is in progress and ensure
it is unlinked on SIGQUIT.

4 years agodaemon: fix SIGUSR2 upgrade with -W0 (no workers)
Eric Wong [Sun, 22 Mar 2020 08:58:48 +0000 (08:58 +0000)]
daemon: fix SIGUSR2 upgrade with -W0 (no workers)

Disabling workers via `-W0' blesses the contents of the
@listeners array, so we need to ensure we call fcntl on
the GLOB ref in ->{sock}.

Add tests to ensure USR2 works regardless of whether workers
are enabled or not.

4 years agov2: SDBM-based multi Message-ID queue
Eric Wong [Fri, 20 Mar 2020 08:18:21 +0000 (08:18 +0000)]
v2: SDBM-based multi Message-ID queue

This lets us store author and committer times for deferred
indexing messages with ambiguous Message-IDs.  This allows
us to reproducibly reindex messages with the git commit
and author times when a rare message lacks Received and/or
Date headers while having ambiguous Message-IDs.

4 years ago*idx: pass smsg in even more places
Eric Wong [Fri, 20 Mar 2020 08:18:20 +0000 (08:18 +0000)]
*idx: pass smsg in even more places

We can finally get rid of the awkward, ad-hoc use of V2Writable,
SearchIdx, and OverIdx args for passing {cotime} and {autime}
between classes.

We'll still use those git time fields internally within
V2Writable and SearchIdx for (re)indexing, but that's not
worth avoiding as a fallback.

4 years agov2: pass smsg in more places
Eric Wong [Fri, 20 Mar 2020 08:18:19 +0000 (08:18 +0000)]
v2: pass smsg in more places

We can pass fewer order-dependent args to V2Writable::do_idx and
SearchIdxShard::index_raw by passing the smsg object, instead.

4 years ago*idx: pass $smsg in more places instead of many args
Eric Wong [Fri, 20 Mar 2020 08:18:18 +0000 (08:18 +0000)]
*idx: pass $smsg in more places instead of many args

We can pass blessed PublicInbox::Smsg objects to internal
indexing APIs instead of having long parameter lists in some
places.  The end goal is to avoid parsing redundant information
each step of the way and hopefully make things more
understandable.

4 years agooveridx: parse_references: less error-prone args
Eric Wong [Fri, 20 Mar 2020 08:18:17 +0000 (08:18 +0000)]
overidx: parse_references: less error-prone args

Favor `$smsg->{mid}' instead of `$mid0' to reduce parameters
down-the-line, but favor passing the Email::MIME::Header object
around instead of relying on the bloat-prone `$smsg->{mime}'
and calling ->header_obj on it.

4 years agosmsg: to_doc_data: use existing fields
Eric Wong [Fri, 20 Mar 2020 08:18:16 +0000 (08:18 +0000)]
smsg: to_doc_data: use existing fields

No need to pass extra parameters to this method, since
smsg has universal meanings for {blob} and {mid}.

4 years agorename PublicInbox::SearchMsg => PublicInbox::Smsg
Eric Wong [Fri, 20 Mar 2020 08:18:15 +0000 (08:18 +0000)]
rename PublicInbox::SearchMsg => PublicInbox::Smsg

Since the introduction of over.sqlite3, SearchMsg is not tied to
our search functionality in any way, so stop confusing ourselves
and future hackers by just calling it "PublicInbox::Smsg".

Add a missing "use" in ExtMsg while we're at it.

4 years agov2writable: preserve timestamps from import
Eric Wong [Fri, 20 Mar 2020 08:18:14 +0000 (08:18 +0000)]
v2writable: preserve timestamps from import

While v2 indexing is triggered immediately after writing the
commit to the git repository, there may be a gap between when
PublicInbox::Import generates a timestamp and when
PublicInbox::SearchIdx sees the message.  So follow the mirror
indexing behavior and take the to-be-indexed (time|date)stamps
directly from the git commit.

4 years agoindex: use git commit times on missing Date/Received
Eric Wong [Fri, 20 Mar 2020 08:18:13 +0000 (08:18 +0000)]
index: use git commit times on missing Date/Received

When indexing messages without Date: and/or Received: headers,
fall back to using timestamps originally recorded by git in the
commit object.  This allows git mirrors to preserve the import
datestamp and timestamp of a message according to what was fed
into git, instead of blindly falling back to the current time.

4 years agot/msgtime: skip test if timezone isn't UTC
Eric Wong [Sat, 21 Mar 2020 06:18:27 +0000 (01:18 -0500)]
t/msgtime: skip test if timezone isn't UTC

Date::Parse falls back to using the local timezone when
it's missing from an email, so only test in a reasonable
TZ (UTC) for server software.

4 years agot/www_listing: avoid 'once' warnings
Eric Wong [Sat, 21 Mar 2020 05:24:32 +0000 (05:24 +0000)]
t/www_listing: avoid 'once' warnings

We reach into the WwwListing package directly to retrieve
that JSON encoder/decoder object, and we can't rely on `use'
since WwwListing loading may fail if Plack is missing.

4 years agowwwlisting: use first successfully loaded JSON module
Eric Wong [Sat, 21 Mar 2020 01:10:33 +0000 (01:10 +0000)]
wwwlisting: use first successfully loaded JSON module

And not the last...

I only noticed this since JSON::PP::Boolean was spewing
redefinition warnings via overload.pm

Fixes: 8fb8fc52420ef669 ("wwwlisting: avoid lazy loading JSON module")
4 years agoexamples/*.psgi: add examples for -httpd
Eric Wong [Thu, 19 Mar 2020 23:55:50 +0000 (23:55 +0000)]
examples/*.psgi: add examples for -httpd

public-inbox-httpd should work with any PSGI files, so make
it more apparent to people reading .psgi examples.

4 years agoviewdiff: favor `qr' to precompile regexps
Eric Wong [Thu, 19 Mar 2020 08:32:56 +0000 (03:32 -0500)]
viewdiff: favor `qr' to precompile regexps

We can also avoid `o' regexp modifier, since it isn't
recommended by Perl upstream, anymore (although we don't
have any bugs or unintended behavior because of it).

4 years agodaemon: do more immortal allocations up front
Eric Wong [Thu, 19 Mar 2020 08:32:55 +0000 (03:32 -0500)]
daemon: do more immortal allocations up front

Doing immortal allocations late can cause those allocations
to end up in places where it fragments the heap.  So do more
things up front for long-lived daemons.

4 years agowww: avoid `state' usage to perform allocations up-front
Eric Wong [Thu, 19 Mar 2020 08:32:54 +0000 (03:32 -0500)]
www: avoid `state' usage to perform allocations up-front

We want WWW->preload to get as many immortal allocations done
as possible, and the `state' feature from Perl 5.10 prevents that.

4 years agowwwlisting: avoid lazy loading JSON module
Eric Wong [Thu, 19 Mar 2020 08:32:53 +0000 (03:32 -0500)]
wwwlisting: avoid lazy loading JSON module

We already lazy-load WwwListing for the CGI script, and
hiding another layer of lazy-loading makes things difficult
to do WWW->preload.

We want long-lived processes to do all long-lived allocations up
front to avoid fragmentation in the allocator, but we'll still
support short-lived processes by lazy-loading individual modules
in the PublicInbox::* namespace.

Mixing up allocation lifetimes (e.g. doing immortal allocations
while a large amount of space is taken by short-lived objects)
will cause fragmentation in any allocator which favors large
contiguous regions for performance reasons.  This includes any
malloc implementation which relies on sbrk() for the primary
heap, including glibc malloc.

4 years agowwwlisting: favor "use" over require
Eric Wong [Thu, 19 Mar 2020 08:32:52 +0000 (03:32 -0500)]
wwwlisting: favor "use" over require

"use" is also evaluated earlier than "require", so it is
favorable for compile-only checking.

4 years agowww: update ->preload for newer modules
Eric Wong [Thu, 19 Mar 2020 08:32:51 +0000 (03:32 -0500)]
www: update ->preload for newer modules

We'll also avoid explicitly loading standard library modules
like POSIX and Digest::SHA, here; instead we load our own
modules and let those load whatever non-PublicInbox:: modules
they need.

4 years agodoc: standards: add references to RFC 5322 (and RFC 822)
Eric Wong [Thu, 19 Mar 2020 07:51:53 +0000 (07:51 +0000)]
doc: standards: add references to RFC 5322 (and RFC 822)

RFC 5322 is the latest one in this line, but much documentation
and even command-line options in other programs (e.g. git) refer
to RFC 2822 or even RFC 822.

4 years agohttp: fix RFC conformance w.r.t. message length
Eric Wong [Tue, 17 Mar 2020 06:52:17 +0000 (06:52 +0000)]
http: fix RFC conformance w.r.t. message length

We need to favor "Transfer-Encoding: chunked" over the value of
the Content-Length header.  We should also reject bogus,
duplicate and/or unreasonable values for both these, since they
can trigger unexpected behavior when combined with other HTTP
parsers in proxies such as varnish, nginx, haproxy, etc...

See RFC 7230 (and RFC 2616) for more details:

https://tools.ietf.org/html/rfc7230
https://www.rfc-editor.org/errata_search.php?rfc=7230

4 years agoINSTALL: refer to the proper Debian version
Eric Wong [Tue, 3 Mar 2020 05:03:11 +0000 (05:03 +0000)]
INSTALL: refer to the proper Debian version

Debian 10.0 was released July 2019, so update our documentation
to reflect that.  While we're at it, fixup a broken footnote
reference for Inline::C, too.

4 years agodaemon: remove unused $parent_pipe variable
Eric Wong [Sat, 7 Mar 2020 12:15:23 +0000 (12:15 +0000)]
daemon: remove unused $parent_pipe variable

We can just create a ParentPipe and let PublicInbox::DS
manage its life cycle.  While we're at it, favor `\&coderef'
over `*coderef' so we're explicit about it being a code ref
and not some other ref type.

4 years agosearchmsg: allow lines (and bytes) to be zero
Eric Wong [Sat, 7 Mar 2020 10:57:02 +0000 (10:57 +0000)]
searchmsg: allow lines (and bytes) to be zero

We will occasionally see legit messages with zero lines,
be sure we index that count for NNTP clients.

I'm not sure about bytes being zero (aside from purged
messages), but we should've dealt with that earlier up
the stack.

4 years agogit: remove POSIX::dup2 import
Eric Wong [Tue, 3 Mar 2020 10:11:20 +0000 (10:11 +0000)]
git: remove POSIX::dup2 import

We rely on spawn/popen_rd for redirects, nowadays.

4 years agospawn: correctly handle error code
Eric Wong [Tue, 3 Mar 2020 09:50:57 +0000 (09:50 +0000)]
spawn: correctly handle error code

Both the C and pure Perl implementions of `pi_fork_exec'
returns `-1' on error, not `undef'.

4 years agomsgtime: assume +0000 if TZ missing when using Date::Parse
Eric Wong [Tue, 25 Feb 2020 09:23:03 +0000 (09:23 +0000)]
msgtime: assume +0000 if TZ missing when using Date::Parse

Some old emails don't have timezone offsets, since our
Date::Parse code path takes a liberal interpretation of dates,
fallback to using "+0000" as the timezone offset since it's
closer to the actual date of the message than whatever the
current date is.

Reported-by: Leah Neukirchen <leah@vuxu.org>
Link: https://public-inbox.org/meta/87h7zfemur.fsf@vuxu.org/
Fixes: ae80a3fdb53d7014 ("MsgTime.pm: Use strptime to compute the time zone")
4 years agoimport: drop '<' and '>' characters in addresses
Eric Wong [Wed, 26 Feb 2020 10:21:12 +0000 (10:21 +0000)]
import: drop '<' and '>' characters in addresses

Some strange "From:" lines will cause Email::Address::XS to
leave '<' (and presumably '>') in the address which
git-fast-import won't accept even if quoted.  Workaround this
problem by deleting '<' and '>' the same way we delete them for
the ident name.

Reported-by: Leah Neukirchen <leah@vuxu.org>
Link: https://public-inbox.org/meta/87h7zfemur.fsf@vuxu.org/
4 years agoINSTALL: update for 1.3.0+, clarify IO::Compress
Eric Wong [Thu, 27 Feb 2020 22:11:50 +0000 (16:11 -0600)]
INSTALL: update for 1.3.0+, clarify IO::Compress

IO::Compress is required for v2 inboxes and overview
indices, after all, but it is often pulled in by
other packages (HTTP::Message via Plack::Test).

4 years agodoc: design_www: document offline friendliness
Eric Wong [Thu, 27 Feb 2020 13:34:51 +0000 (13:34 +0000)]
doc: design_www: document offline friendliness

This isn't anything new and has been a part of the design
since the beginning, but it may not be apparent to some
folks.

4 years agosearchview: improve naming and simplify hash override
Eric Wong [Wed, 26 Feb 2020 00:44:05 +0000 (00:44 +0000)]
searchview: improve naming and simplify hash override

`%over' could be confused for the overview SQLite DB
instance, so call it `%override', instead.  There's
also no need to write a loop to override a hash when
the language can do it for us.

4 years agodoc: 1.4.0 release notes update
Eric Wong [Tue, 25 Feb 2020 22:57:38 +0000 (16:57 -0600)]
doc: 1.4.0 release notes update

Perhaps 1.4.0 will be a small release, after all (and also
smaller in terms of memory use :)

4 years agov2writable: lookup_content => content_exists
Eric Wong [Mon, 24 Feb 2020 08:08:22 +0000 (08:08 +0000)]
v2writable: lookup_content => content_exists

It only needs to return a boolean, since none of the current
callers care about the return value.  Thus avoid a hash table
assignment and use of `$smsg->{mime}', here.

4 years agov2writable: make remove return-compatible w/ Import::remove
Eric Wong [Mon, 24 Feb 2020 08:08:21 +0000 (08:08 +0000)]
v2writable: make remove return-compatible w/ Import::remove

Import::remove is a documented interface, and the return
value of the V2Writable work-alike should try to be compatible
with what Import implements.

4 years agoexamples/nginx_proxy: convert CRLF to LF
Eric Wong [Mon, 24 Feb 2020 07:33:28 +0000 (07:33 +0000)]
examples/nginx_proxy: convert CRLF to LF

It was the only file in our tree which had CRLF line endings,
so make it consistent with the rest.