]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
4 years agogithttpbackend: split out wwwstatic
Eric Wong [Wed, 25 Dec 2019 07:50:48 +0000 (07:50 +0000)]
githttpbackend: split out wwwstatic

Make it easier to share code between our GitHTTPBackend and Cgit
packages, for now, and possibly other packages in the future.

We can avoid inline_object and anonymous subs at the same
time, reducing per-request memory overhead.

4 years agoqspawn: psgi_return: allow non-anon parse_hdr callback
Eric Wong [Wed, 25 Dec 2019 07:50:47 +0000 (07:50 +0000)]
qspawn: psgi_return: allow non-anon parse_hdr callback

Callers can supply an arg to parse_hdr, now, eliminating the
need for closures to capture local variables.

4 years agoqspawn: drop "qspawn.filter" support, for now
Eric Wong [Wed, 25 Dec 2019 07:50:46 +0000 (07:50 +0000)]
qspawn: drop "qspawn.filter" support, for now

This feature was added in preparation for future changes
that have yet to materialize after nearly 3 years.  We
can re-add it if needed in the future.

4 years agoqspawn: psgi_qx: eliminate anonymous subs
Eric Wong [Wed, 25 Dec 2019 07:50:45 +0000 (07:50 +0000)]
qspawn: psgi_qx: eliminate anonymous subs

We can follow what we did in psgi_return to make psgi_qx
allocate less memory on each call.

4 years agoqspawn: psgi_return_start: hoist out from psgi_return
Eric Wong [Wed, 25 Dec 2019 07:50:44 +0000 (07:50 +0000)]
qspawn: psgi_return_start: hoist out from psgi_return

Instead of just passing the rpipe to the start_cb, pass the
entire qspawn ref to start_cb.  Update existing callers to
avoid circular refs.

4 years agoqspawn: psgi_return: initial cb can be named
Eric Wong [Wed, 25 Dec 2019 07:50:43 +0000 (07:50 +0000)]
qspawn: psgi_return: initial cb can be named

We can take advantage of HTTPD::Async being able to pass
user-supplied args to callbacks to get rid of one (of many)
anonymous subs in the code path.

4 years agohttpd/async: get rid of ephemeral main_cb
Eric Wong [Wed, 25 Dec 2019 07:50:42 +0000 (07:50 +0000)]
httpd/async: get rid of ephemeral main_cb

Cheaper to use up two hash table slots than creating a new sub.

4 years agoqspawn: reduce local vars, de-anonymize rd_hdr
Eric Wong [Wed, 25 Dec 2019 07:50:41 +0000 (07:50 +0000)]
qspawn: reduce local vars, de-anonymize rd_hdr

rd_hdr() now becomes a named subroutine instead of a per-call
local variable, so kilobytes of memory will not have to be
allocated for it on every ->psgi_return call.

4 years agomsg_iter: provide means to stop using anonymous subs
Eric Wong [Wed, 25 Dec 2019 07:50:40 +0000 (07:50 +0000)]
msg_iter: provide means to stop using anonymous subs

And remove the last anonymous sub in SolverGit itself.

4 years agoqspawn: replace anonymous $end callbacks w/ event_step
Eric Wong [Wed, 25 Dec 2019 07:50:39 +0000 (07:50 +0000)]
qspawn: replace anonymous $end callbacks w/ event_step

This will tie into the DS event loop if that's used, but
event_step an be called directly without relying on the
event loop from Apache or other HTTP servers (or PSGI tests).

4 years agoqspawn: disambiguate command vs PSGI env
Eric Wong [Wed, 25 Dec 2019 07:50:38 +0000 (07:50 +0000)]
qspawn: disambiguate command vs PSGI env

Make things easier-to-follow and paves the way for future work
to reduce dependencies on anonymous subs capturing local variables.

4 years agoqspawn: remove some anonymous subs for psgi_qx
Eric Wong [Wed, 25 Dec 2019 07:50:37 +0000 (07:50 +0000)]
qspawn: remove some anonymous subs for psgi_qx

By passing a user-supplied arg to $qx_cb, we can eliminate the
callers' need to capture on-stack variables with a closure.
This saves several kilobytes of memory allocation at the expense
of some extra hash table lookups in user-supplied callbacks.  It
also reduces the risk of memory leaks by eliminating a common
source of circular references.

4 years agohttpd/async: support passing arg to callbacks
Eric Wong [Wed, 25 Dec 2019 07:50:36 +0000 (07:50 +0000)]
httpd/async: support passing arg to callbacks

Another step towards removing anonymous subs to eliminate
a possible source of memory leaks and high memory use.

4 years agogit: allow async_cat to pass arg to callback
Eric Wong [Wed, 25 Dec 2019 07:50:35 +0000 (07:50 +0000)]
git: allow async_cat to pass arg to callback

This allows callers to avoid allocating several KB for for every
call to ->async_cat.

4 years agowwwlisting: do not rely on $? after ProcessPipe::CLOSE
Eric Wong [Thu, 26 Dec 2019 10:47:12 +0000 (10:47 +0000)]
wwwlisting: do not rely on $? after ProcessPipe::CLOSE

ProcessPipe::CLOSE won't reliably set $? inside the event loop
if waitpid(..., WNOHANG) isn't successful.  So use a blocking
waitpid() call, here, and hope "git show-ref" exits promptly
since we've already drained its stdout.

4 years agot/solver_git: test with -httpd, too
Eric Wong [Thu, 26 Dec 2019 06:48:04 +0000 (06:48 +0000)]
t/solver_git: test with -httpd, too

Solver uses the internal -httpd async API if available for
fairness when applying large patchsets.  We must test those
code paths in addition to the generic PSGI code paths.

4 years agot/www_listing: test "all" HTML listing
Eric Wong [Thu, 26 Dec 2019 06:48:03 +0000 (06:48 +0000)]
t/www_listing: test "all" HTML listing

We now have coverage for PublicInbox::WwwListing::list_all.

4 years agot/www_listing: quiet down stderr in -httpd
Eric Wong [Thu, 26 Dec 2019 06:48:02 +0000 (06:48 +0000)]
t/www_listing: quiet down stderr in -httpd

We need to init all.git for the v2 repo test to ensure
`git --git-dir=v2/all.git rev-parse --git-path objects/info/alternates`
doesn't warn or fail and clutter stderr.  This is noticeable
when setting TAIL="tail -F" in env before running this test.

4 years agot/psgi_v2: test search results Atom feed endpoint
Eric Wong [Wed, 25 Dec 2019 06:19:47 +0000 (06:19 +0000)]
t/psgi_v2: test search results Atom feed endpoint

The "x=A" search results endpoint finally gets test coverage.

4 years agot/search.t: update permissions check for OpenBSD
Eric Wong [Sun, 22 Dec 2019 22:17:40 +0000 (22:17 +0000)]
t/search.t: update permissions check for OpenBSD

OpenBSD (tested 6.5 on amd64) seems to follow the same semantics
as FreeBSD for S_ISGID, even if config.mak.uname in git.git
doesn't say so.

4 years agosearch: support SWIG-generated Xapian.pm
Eric Wong [Sun, 22 Dec 2019 22:17:39 +0000 (22:17 +0000)]
search: support SWIG-generated Xapian.pm

Xapian upstream is slowly phasing out the XS-based Search::Xapian
in favor of the SWIG-generated "Xapian" package.  While Debian and
both FreeBSD have Search::Xapian, OpenBSD only includes the "Xapian"
binding.

More information about the status of the "Xapian" Perl module here:
https://trac.xapian.org/ticket/523

4 years agosearchidx: call "++" on PostingIterator instead of "->inc"
Eric Wong [Sun, 22 Dec 2019 22:17:38 +0000 (22:17 +0000)]
searchidx: call "++" on PostingIterator instead of "->inc"

The "++" is not yet available in the SWIG-based "Xapian.pm" Perl
bindings, so use "++" where it's supported in both the XS
(Search::Xapian) and SWIG-based Xapian binding.

4 years agotestcommon: add require_mods method and use it
Eric Wong [Sun, 22 Dec 2019 22:17:37 +0000 (22:17 +0000)]
testcommon: add require_mods method and use it

This cuts down on lines of code in individual test cases and
fixes some misnamed error messages by using "$0" consistently.

This will also provide us with a method of swapping out
dependencies which provide equivalent functionality (e.g
"Xapian" SWIG can replace "Search::Xapian" XS bindings).

4 years agoremove "no warnings 'once'" in a few places
Eric Wong [Mon, 23 Dec 2019 23:06:03 +0000 (23:06 +0000)]
remove "no warnings 'once'" in a few places

We can use "use" to get the namespace into the "BEGIN" phase of
the interpreter.  While we're at it, use \&coderef syntax
explicitly instead of globbing everything.

4 years agonntp: cmd_xover: use named sub for long_response
Eric Wong [Sat, 21 Dec 2019 08:00:07 +0000 (08:00 +0000)]
nntp: cmd_xover: use named sub for long_response

Introduce xover_i, which does the same thing as the anonymous
sub it replaces.

4 years agonntp: hdr_msg_id: use named sub for long_response
Eric Wong [Sat, 21 Dec 2019 08:00:06 +0000 (08:00 +0000)]
nntp: hdr_msg_id: use named sub for long_response

Introduce hdr_msgid_range_i, which does the same thing as the
anonymous sub it replaces.

4 years agonntp: cmd_newnews: use named sub for long_response
Eric Wong [Sat, 21 Dec 2019 08:00:05 +0000 (08:00 +0000)]
nntp: cmd_newnews: use named sub for long_response

Introduce newnews_i, which does the same thing as the anonymous
sub it replaces.

4 years agonntp: cmd_listgroup: use named subs for long_response
Eric Wong [Sat, 21 Dec 2019 08:00:04 +0000 (08:00 +0000)]
nntp: cmd_listgroup: use named subs for long_response

Introduce listgroup_range_i and listgroup_all_i subs which
do the same things as the anonymous subs they replace.

4 years agonntp: cmd_xrover: use named sub for long_response
Eric Wong [Sat, 21 Dec 2019 08:00:03 +0000 (08:00 +0000)]
nntp: cmd_xrover: use named sub for long_response

Introduce xrover_i which does the same thing as the anonymous
sub it replaces.

4 years agonntp: hdr_searchmsg: use named sub for numeric range response
Eric Wong [Sat, 21 Dec 2019 08:00:02 +0000 (08:00 +0000)]
nntp: hdr_searchmsg: use named sub for numeric range response

Introduce searchmsg_range_i, which does the same thing as
the anonymous sub it replaces.

4 years agonntp: remove cyclic refs from long_response
Eric Wong [Sat, 21 Dec 2019 08:00:01 +0000 (08:00 +0000)]
nntp: remove cyclic refs from long_response

Leftover cyclic references are a source of memory leaks.  While
our code is AFAIK unaffected by such leaks at the moment,
eliminating a potential source of bugs will make maintenance
easier.

We make the long_response API cycle-free by stashing the
callback into the NNTP object.  However, callers will need
to be updated to get rid of the circular reference to $self.
We do that be replacing anonymous subs with name subroutine
references, such as xref_range_i replacing the formerly
anonymous sub inside hdr_xref.

4 years agonntp: get_range: return scalarref for $beg
Eric Wong [Sat, 21 Dec 2019 08:00:00 +0000 (08:00 +0000)]
nntp: get_range: return scalarref for $beg

...Instead of just returning a plain scalar inside an arrayref.

This is because we usually pass the result of NNTP::get_range to
Msgmap::msg_range.  Upcoming changes will move us away from
anonymous subroutines, so this change will make followup commits
easier-to-digest as modifications to the underlying scalar can
be more easily propagated between non-anonymous-subs.

4 years agohttp: avoid anonymous sub for getline callback
Eric Wong [Sat, 21 Dec 2019 23:53:19 +0000 (23:53 +0000)]
http: avoid anonymous sub for getline callback

We can avoid the danger of self-referential subs entirely for
code internal to PublicInbox::HTTP.

This change was only made possible by
commit 8e1c3155da4edc082e8e3d8b30351f0c861757a7
("ds: pass $self to code references")

4 years agohttp: get rid of anonymous subs for write/close
Eric Wong [Sat, 21 Dec 2019 23:53:18 +0000 (23:53 +0000)]
http: get rid of anonymous subs for write/close

Each sub costs us several kilobytes of memory for every
response we make.  An arrayref only costs 80 bytes on
64-bit, so bless that to packages with appropriate ->write
and ->close methods.

4 years agonntp: get rid of some unused imports
Eric Wong [Sun, 22 Dec 2019 00:12:12 +0000 (00:12 +0000)]
nntp: get rid of some unused imports

Our NNTP code no longer relies on search or Xapian.  Msgmap
and Git modules are loaded anyways through Inbox->(git|mm|over)
methods, however.

4 years agonntp: simplify method detection using UNIVERSAL::can
Eric Wong [Sun, 22 Dec 2019 00:12:45 +0000 (00:12 +0000)]
nntp: simplify method detection using UNIVERSAL::can

No need to do an eval dance or disable strict refs.

4 years agotestcommon: require_git: use "plan" from Test::More
Eric Wong [Sun, 22 Dec 2019 03:54:46 +0000 (03:54 +0000)]
testcommon: require_git: use "plan" from Test::More

require_git is no longer in the "::main" namespace, so we must
call Test::More::plan() explicitly.

4 years agosearchview: save a column in &x=t thread skeleton
Eric Wong [Fri, 20 Dec 2019 06:58:27 +0000 (06:58 +0000)]
searchview: save a column in &x=t thread skeleton

Displaying "100%" wastes a precious column.  Show "99%" instead
since there's little practical difference and <xapian/mset.h>
states:

  Note that these generally aren't percentages of anything meaningful
  (unless you use a custom weighting formula where they are!)

And we're not using a custom weighting formula.

4 years agoview: show percentage in search results thread skeleton
Eric Wong [Thu, 19 Dec 2019 05:18:01 +0000 (05:18 +0000)]
view: show percentage in search results thread skeleton

The displays the Xapian ->get_percent value in the skeleton to
improve scanning of relevancy; irrelevant results do not display
that.

This fixes broken #anchor links introduced in the previous
commit, irrelevant messages now link to the /$INBOX/$MESSAGE_ID page.

4 years agosearchthread: fix usage of user-supplied parameter
Eric Wong [Thu, 19 Dec 2019 05:18:00 +0000 (05:18 +0000)]
searchthread: fix usage of user-supplied parameter

Instead of only passing an Inbox object, we'll pass the $ctx
reference as PublicInbox::SearchView::mset_thread did.

So although mset_thread was wrong, we now make it's usage
of SearchThread::thread correct and update other callers to
favor the new style of passing the entire $ctx (with ->{-inbox})
instead of just the Inbox object.

This makes the thread skeleton at the bottom of the search
page to show subjects of messages, but unfortunately links to
non-existent #anchors.  The next commit will fix that.

While we're at it, favor "\&foo" over "*foo" since the former
makes the code reference (aka "function pointer) obvious so it
won't be confused for other things named "foo" in that
scope (e.g. $foo/@foo/%foo).

4 years agotestcommon: fix run_script for older Perls
Eric Wong [Thu, 19 Dec 2019 08:38:51 +0000 (08:38 +0000)]
testcommon: fix run_script for older Perls

Using Perl "open" to dup(2) and save the old handles is required
since "local *STDIN = *STDIN" does not work on old Perls.  Even
worse, this was silently a no-op when tested with Perl 5.24.1 on
Debian 9.x and led to confusing failures in the t/httpd-corner.t
lsof(1) tests when run after t/v2mirror.t from the same worker
process using t/run.perl.

4 years agot/run.perl: to avoid repeated process spawning for *.t
Eric Wong [Wed, 18 Dec 2019 03:36:45 +0000 (03:36 +0000)]
t/run.perl: to avoid repeated process spawning for *.t

Spawning a new Perl interpreter for every test case
means Perl has to reparse and recompile every single file
it needs, costing us performance and development time.

Now that we've modified our code to avoid global state,
we can preload everything we need.

The new "check-run" test target is now 20-30% faster
than the original "check" target.

4 years agotests: move t/common.perl to PublicInbox::TestCommon
Eric Wong [Wed, 18 Dec 2019 03:36:44 +0000 (03:36 +0000)]
tests: move t/common.perl to PublicInbox::TestCommon

We want to be able to use run_script with *.t files, so
t/common.perl putting subs into the top-level "main" namespace
won't work.  Instead, make it a module which uses Exporter
like other libraries.

4 years agot/*.t: avoid sharing "my" variables in subs
Eric Wong [Wed, 18 Dec 2019 03:36:43 +0000 (03:36 +0000)]
t/*.t: avoid sharing "my" variables in subs

These usages of file-local global variables make the *.t files
incompatible with run_script().  Instead, use anonymous subs,
"our", or pass the parameter as appropriate.

4 years agomsgiter: msg_part_text returns undef on text/html
Eric Wong [Wed, 18 Dec 2019 09:14:43 +0000 (09:14 +0000)]
msgiter: msg_part_text returns undef on text/html

We want HTML parts to be downloadable, but not displayed as
unreadable (but injection-safe) HTML source in our own web
and Atom interfaces.

This affects indexing, too, as HTML tags/comments won't be
indexed anymore, but existing indices are only cleaned after
--reindex.  HTML-only mail won't be indexed at all, but we won't
cross that bridge until somebody cares about that crap.   We'll
continue to actively discourage such waste of CPU cycles,
bandwidth, cache and storage.

Fixes: 7d82a8bc04ce2e68 (handle "multipart/mixed" messages which are not multipart')
4 years agoMakefile.PL: sort target and var lists
Eric Wong [Wed, 18 Dec 2019 03:36:42 +0000 (03:36 +0000)]
Makefile.PL: sort target and var lists

Sorting makes it easier to review the generated result.

4 years agoviewvcs: flesh out some functionality and test
Eric Wong [Wed, 18 Dec 2019 03:36:41 +0000 (03:36 +0000)]
viewvcs: flesh out some functionality and test

Expose MAX_SIZE via "our" will make it possible
to use in tests, and configure, later.

Additionally, returning HTTP 500 code for big files is not an
Internal Server Error, just a memory limit...  Some browsers
won't show our HTML response with the link to the raw file in
case of errors, either, so we'll return 200 to ensure users can
use the link to access the raw blob.

Finally, throw in some tests to the existing solver_git testcase,
since that was incomplete and was pointlessly loading Plack
modules without testing PSGI.

4 years agoTODO: add UUCP address item
Eric Wong [Wed, 18 Dec 2019 03:36:40 +0000 (03:36 +0000)]
TODO: add UUCP address item

We should support historical archives from the old days,
but I'm not sure how to best go about it, for now, given
how tricky correct handling of modern email addresses is.
We can deal with it if/when somebody decides to import some
ancient archives...

4 years agoMakefile.PL: allow overriding "prove" from make CLI
Eric Wong [Sat, 14 Dec 2019 18:06:59 +0000 (18:06 +0000)]
Makefile.PL: allow overriding "prove" from make CLI

Development versions of Perl install "prove$VERSION"
where $VERSION is something like "5.31.7".  This makes
it easier to test everything we have against development
versions of Perl5.

Note: I could not find a way to get quoting right to use the
"--exec $(PERL)" option of prove(1), but that would be the best
option for working transparently after running:

perl5.31.7 Makefile.PL

4 years agot/edit.t: drop redundant "delete local $ENV{...}"
Eric Wong [Mon, 16 Dec 2019 08:07:34 +0000 (08:07 +0000)]
t/edit.t: drop redundant "delete local $ENV{...}"

"delete local" is only in Perl v5.11.0, and we only depend on
Perl v5.10.1.  We already localize and delete it as two separate
statements immediately above.

I wish this was hidden behind a "use feature" flag like other
new-fangled things :<.  Oh well, I think the oldest Perl actually
in use for this project is 5.16 (CentOS 7.x).

4 years agodaemon: drop listeners early in master on graceful shutdown
Eric Wong [Sun, 15 Dec 2019 23:11:07 +0000 (23:11 +0000)]
daemon: drop listeners early in master on graceful shutdown

For users not relying on socket activation via systemd (or
similar), we want to drop listeners ASAP so another process
can bind to their address.  While we're at it, disable
TTIN and HUP handlers since we have no chance of starting
usable workers without listeners.

4 years agodaemon: shorten lifetime of listener_names mapping
Eric Wong [Sun, 15 Dec 2019 23:11:06 +0000 (23:11 +0000)]
daemon: shorten lifetime of listener_names mapping

Keeping a ref to the IO::Socket handle was preventing
close(2) from being invoked on graceful shutdown of
worker.

4 years agoaddress: explicitly reject local-only addresses
Eric Wong [Sat, 14 Dec 2019 05:22:18 +0000 (05:22 +0000)]
address: explicitly reject local-only addresses

Apparently, neither our previous address parsing code nor
Email::Address::XS recognizes local, username-only addresses
in the form of <username> (without "@host").  Without
this change, Email::Address::XS->address would return
"undef", so we need to filter it out via "grep { defined }"

It seems the cases where users email each other on the same
machine is small and public-inbox won't be able to index
addresses for those cases...  Oh well :/

4 years agoaddress: use Email::Address::XS if available
Eric Wong [Sat, 14 Dec 2019 01:02:56 +0000 (01:02 +0000)]
address: use Email::Address::XS if available

Email::Address::XS is a dependency of modern versions of Email::MIME,
so it's likely loaded and installed on newer systems, already;
and capable of handling more corner-cases than our pure-Perl
fallback.

We still fallback to the imperfect-but-good-enough-in-practice
pure-Perl code while avoiding the non-XS Email::Address (which
was susceptible to DoS attacks (CVE-2015-7686)).  We just need
to keep "git fast-import" happy.

4 years agoaddress: use comment as name if no phrase available
Eric Wong [Sat, 14 Dec 2019 01:02:55 +0000 (01:02 +0000)]
address: use comment as name if no phrase available

Some users will set their From: headers in the form of:
"<user@example.com> (A U Thor)", where their name is in
the parenthesized comment.  Use that instead of the
email address, if available.

4 years agoinbox: fix periodic git process cleanup
Eric Wong [Sun, 15 Dec 2019 08:35:30 +0000 (08:35 +0000)]
inbox: fix periodic git process cleanup

We need to use $PublicInbox::DS::in_loop instead of ::running().
The latter is not valid for systems with signalfd or kqueue and
is now gone, completely.

Not needing periodic cleanups at all to deal with unlinked pack
indices will be a tougher task...

4 years agosearchidx: do not modify read-only $1 via git_unquote
Eric Wong [Sun, 15 Dec 2019 03:37:56 +0000 (03:37 +0000)]
searchidx: do not modify read-only $1 via git_unquote

git_unquote works in-place, and we sometimes see strange
filenames, or badly munged diffs with terminal escape
characters (for colorization) end up in emails.

4 years agodaemon: use DESTROY for unlinking --pid-file
Eric Wong [Thu, 12 Dec 2019 21:16:49 +0000 (21:16 +0000)]
daemon: use DESTROY for unlinking --pid-file

This gets rid of the last "END{}" block in our code and cleans
up a (temporary) circular reference.

Furthermore, ensure the cleanup code still works in all
configurations by adding tests and testing both the -W1
(default, 1 worker) and -W0 (no workers) code paths.

4 years agods: move NNTP-only expiration code into DS
Eric Wong [Thu, 12 Dec 2019 21:16:48 +0000 (21:16 +0000)]
ds: move NNTP-only expiration code into DS

We'll be supporting idle timeout for the HTTP code in the
future to deal directly with Internet-exposed clients w/o
Varnish or nginx.

4 years agods: move EvCleanup code into DS
Eric Wong [Thu, 12 Dec 2019 21:16:47 +0000 (21:16 +0000)]
ds: move EvCleanup code into DS

EvCleanup only existed since Danga::Socket was a separate
component, and cleanup code belongs with the event loop.

4 years agoMakefile.PL: fix "dsyn" target
Eric Wong [Thu, 12 Dec 2019 08:04:53 +0000 (08:04 +0000)]
Makefile.PL: fix "dsyn" target

The "dsyn" target needs to remain working, despite still
being dependent on GNU-isms at the moment.

Fixes: 73fe3421f1ecbdc8 ("build: support doc generation w/o GNU make")
4 years agombox: do not try to create filename from empty string
Eric Wong [Thu, 12 Dec 2019 08:03:39 +0000 (08:03 +0000)]
mbox: do not try to create filename from empty string

This was causing warnings to pop up in syslogs for messages with
empty Subject headers.

4 years agomsgtime: avoid obviously out-of-range dates (for now)
Eric Wong [Sun, 1 Dec 2019 22:04:25 +0000 (22:04 +0000)]
msgtime: avoid obviously out-of-range dates (for now)

Wacky dates show up in lore for valid messages.  Lets ignore
them and let future generations deal with Y10K and time-travel
problems.

4 years agoDate::Parse is now optional
Eric Wong [Fri, 29 Nov 2019 12:25:08 +0000 (12:25 +0000)]
Date::Parse is now optional

-mda should not be dealing with broken Date: headers
nowadays, and deprioritize it in our documentation and
internal checks.

4 years agomsgtime: drop Date::Parse for RFC2822
Eric Wong [Fri, 29 Nov 2019 12:25:07 +0000 (12:25 +0000)]
msgtime: drop Date::Parse for RFC2822

Date::Parse is not optimized for RFC2822 dates and isn't
packaged on OpenBSD.  It's still useful for historical
email when email clients were less conformant, but is
less relevant for new emails.

4 years agoadd msgtime_cmp maintainer test
Eric Wong [Fri, 29 Nov 2019 12:25:06 +0000 (12:25 +0000)]
add msgtime_cmp maintainer test

Changes will be coming for MsgTime to stop depending on
Date::Parse due to lack of package availability on OpenBSD
and suboptimal performance on RFC822 dates.

4 years agogit: async batch interface
Eric Wong [Fri, 29 Nov 2019 12:25:05 +0000 (12:25 +0000)]
git: async batch interface

This is a transitionary interface which does NOT require an
event loop.  It can be plugged into in current synchronous code
without major surgery.

It allows HTTP/1.1 pipelining-like functionality by taking
advantage of predictable and well-specified POSIX pipe semantics
by stuffing multiple git cat-file requests into the --batch pipe

With xt/git_async_cmp.t and GIANT_GIT_DIR=git.git, the async
interface is 10-25% faster than the synchronous interface since
it can keep the "git cat-file" process busier.

This is expected to improve performance on systems with slower
storage (but multiple cores).

4 years agobuild: support doc generation w/o GNU make
Eric Wong [Sun, 1 Dec 2019 10:50:19 +0000 (10:50 +0000)]
build: support doc generation w/o GNU make

We can replace the GNU-isms for building docs with Perl5
equivalents.  The only downside is the resulting Makefile
gets larger, but that's the price of portability.

4 years agoimport: (cleanup) drop redundant env arg to run_die
Eric Wong [Fri, 29 Nov 2019 10:14:14 +0000 (10:14 +0000)]
import: (cleanup) drop redundant env arg to run_die

run_die() doesn't require an $env arg, so there's no
point passing "undef" to it.

4 years agospawn: remove support for clearing the env
Eric Wong [Fri, 29 Nov 2019 10:14:13 +0000 (10:14 +0000)]
spawn: remove support for clearing the env

It's unnecessary code which I'm not sure we ever used.  In
retrospect, completely clearing the environment doesn't make
sense for the processes we spawn.  We don't need to clobber
individual environment variables in our code, either
(and if we did for tests, we can use 'local').

4 years agotests: don't repeatly validate NEWS.atom
Eric Wong [Fri, 29 Nov 2019 10:14:12 +0000 (10:14 +0000)]
tests: don't repeatly validate NEWS.atom

We can create a stamp to avoid rerunning the check unless
NEWS.atom changes (and it will, soon, I hope :>).

4 years agoTODO: update and add a few more items
Eric Wong [Fri, 29 Nov 2019 10:14:11 +0000 (10:14 +0000)]
TODO: update and add a few more items

SpamAssassin has used re2c (via sa-compile) for many years, now,
and it seems to work fine, there.  GMime also looks promising
when combined with Inline::C since GMime can operate on mmap-ed
regions.

Given the inevitable demise of many .orgs when price rise;
supporting a URL rewriter similar to .mailmap makes sense.

And HTTP CONNECT seems like something our -httpd can support
to let firewalled users read over NNTP.

4 years agods: ->Reset initializes $nextq
Eric Wong [Fri, 29 Nov 2019 10:14:10 +0000 (10:14 +0000)]
ds: ->Reset initializes $nextq

I haven't noticed this being a problem in practice, but
be consistent with the rest of the singleton stuff.
Since we always call Reset() at load time, only do
initialization in that sub and not at declaration.

4 years agot/common: set $0 when running script w/o fork
Eric Wong [Fri, 29 Nov 2019 10:14:09 +0000 (10:14 +0000)]
t/common: set $0 when running script w/o fork

We can localize changes to $0 so $0 is restored when the
"script" sub is done.  This will be helpful when we encounter
a stuck/slow processes during our tests (hopefully never!)

4 years agot: localize the PI_CONFIG env
Eric Wong [Fri, 29 Nov 2019 10:14:08 +0000 (10:14 +0000)]
t: localize the PI_CONFIG env

We don't want the user's ~/.public-inbox/config to be read from
during tests.  I only noticed this because I had a non-existent
pathname for one of my inboxes :x

I've also verified this change by running "inotifywait
~/.public-inbox/config -m" in another terminal while running
"make check"; (perhaps a portable solution could make it
into the test suite).

4 years agoreplace: quiet "git gc" invocation
Eric Wong [Thu, 28 Nov 2019 20:54:35 +0000 (20:54 +0000)]
replace: quiet "git gc" invocation

Since we give users no indication or control of how "git gc"
runs, showing its progress is confusing.

4 years agot/replace: quiet "git fsck" invocation
Eric Wong [Thu, 28 Nov 2019 20:54:34 +0000 (20:54 +0000)]
t/replace: quiet "git fsck" invocation

Test output can be a terminal if running as "perl -I lib t/$FOO.t",
and showing fsck progress is pointless for tests.

4 years agot/httpd-unix: FreeBSD expects to fail with EADDRINUSE
Eric Wong [Thu, 28 Nov 2019 07:08:54 +0000 (07:08 +0000)]
t/httpd-unix: FreeBSD expects to fail with EADDRINUSE

Tested FreeBSD 11.2.  I'm starting to think I'm too conservative
with this check and it could be safely expanded to cover any OS
with UNIX sockets.

4 years agoMakefile.PL: MANIFEST dependency fix
Eric Wong [Wed, 27 Nov 2019 11:07:18 +0000 (11:07 +0000)]
Makefile.PL: MANIFEST dependency fix

We need to force an update to Makefile (not Makefile.PL) when
MANIFEST changes.  Since "Makefile" (aka. "$(FIRST_MAKEFILE)")
is already a single-colon make target; we can't create a
double-colon rule to augment it.  So we'll continue using a
"Makefile.PL" rule, but have it recreate the resulting Makefile

Finally, change the "check" target to use "prove -b" instead of
"prove -l" so we test against "blib/lib", since what's in the
"blib" dir will be installed.

Fixes: 4c20de0694d06ff3 ("Makefile.PL: add dependency on MANIFEST contents")
4 years agohttpd|nntpd: avoid missed signal wakeups
Eric Wong [Wed, 27 Nov 2019 01:33:33 +0000 (01:33 +0000)]
httpd|nntpd: avoid missed signal wakeups

Our attempt at using a self-pipe in signal handlers was
ineffective, since pure Perl code execution is deferred
and Perl doesn't use an internal self-pipe/eventfd.  In
retrospect, I actually prefer the simplicity of Perl in
this regard...

We can use sigprocmask() from Perl, so we can introduce
signalfd(2) and EVFILT_SIGNAL support on Linux and *BSD-based
systems, respectively.  These OS primitives allow us to avoid a
race where Perl checks for signals right before epoll_wait() or
kevent() puts the process to sleep.

The (few) systems nowadays without signalfd(2) or IO::KQueue
will now see wakeups every second to avoid missed signals.

4 years agodskqxs: fix missing EV_DISPATCH define
Eric Wong [Wed, 27 Nov 2019 01:33:32 +0000 (01:33 +0000)]
dskqxs: fix missing EV_DISPATCH define

Oops, IO::KQueue support was broken due to this missing
constant.  Add a new ds-kqxs.t test case to ensure we
test the IO::KQueue path if IO::KQueue is available.

4 years agomsgtime: deal with strange minutes in TZ offsets
Eric Wong [Mon, 25 Nov 2019 05:24:54 +0000 (05:24 +0000)]
msgtime: deal with strange minutes in TZ offsets

I'm not sure if TZ minute offsets aside from '00' or '30' exist,
but lets just deal with them properly when negative.  Examples
taken from various inboxes on lore.kernel.org.  These are mostly
message from spammers, but some are legitimate messages.

4 years agot/msgtime: add more checks for known cases
Eric Wong [Mon, 25 Nov 2019 05:24:53 +0000 (05:24 +0000)]
t/msgtime: add more checks for known cases

Broken email clients sent the darndest things, make sure
we can still support them when we make Date::Parse optional.

4 years agot/msgtime: show date in test descriptions
Eric Wong [Mon, 25 Nov 2019 05:24:52 +0000 (05:24 +0000)]
t/msgtime: show date in test descriptions

Otherwise it's hard to figure what fails.

4 years agotests: move giant inbox/git dependent tests to xt/
Eric Wong [Sun, 24 Nov 2019 00:22:37 +0000 (00:22 +0000)]
tests: move giant inbox/git dependent tests to xt/

xt/ is typically reserved for "eXtended tests" intended for
the maintainers and not ordinary users.  Since these require
special configuration and do nothing by waste cycles
during startup, they qualify.

4 years agot/perf-*.t: use $ENV{GIANT_INBOX_DIR} consistently
Eric Wong [Sun, 24 Nov 2019 00:22:36 +0000 (00:22 +0000)]
t/perf-*.t: use $ENV{GIANT_INBOX_DIR} consistently

It's more consistent with our current terminology and
"PI_DIR" is already used to override ~/.public-inbox/
(which holds "config" and possibly other files which affect
all inboxes for a particular user, but is not an inbox itself);
so stop advertising GIANT_PI_DIR in skip messages.

4 years agotests: quiet down commit graph
Eric Wong [Sun, 24 Nov 2019 00:22:35 +0000 (00:22 +0000)]
tests: quiet down commit graph

Newer versions of git enable the commit graph by default.
Since we blow away our temporary directories every test,
generating graphis is a waste and clutters stderr with
"Computing commit graph generation numbers" messages.

4 years agotests: use File::Temp->newdir instead of tempdir()
Eric Wong [Sun, 24 Nov 2019 00:22:34 +0000 (00:22 +0000)]
tests: use File::Temp->newdir instead of tempdir()

We'll also introduce a tmpdir() API to give tempdirs
consistent names.

4 years agoxapcmd: replace Xtmpdirs with File::Temp->newdir
Eric Wong [Sun, 24 Nov 2019 00:22:33 +0000 (00:22 +0000)]
xapcmd: replace Xtmpdirs with File::Temp->newdir

Since we're using Perl 5.10.1 and File::Temp 0.19+, we don't
need Xtmpdirs at all for cleaning up tempdirs on failure and
can just rely on the DESTROY handler provided by File::Temp.

4 years agot/nntpd-validate: get rid of threads dependency
Eric Wong [Sun, 24 Nov 2019 00:22:32 +0000 (00:22 +0000)]
t/nntpd-validate: get rid of threads dependency

Threads are officially discouraged by perl5-porters and proves
problematic with my Perl installation when using run_mode=1
to speed up tests.  So just use fork() and pipes to share
results from Net::NNTP.

4 years agot/common: start_script replaces spawn_listener
Eric Wong [Sun, 24 Nov 2019 00:22:31 +0000 (00:22 +0000)]
t/common: start_script replaces spawn_listener

We can shave several hundred milliseconds off tests which spawn
daemons by preloading and avoiding startup time for common
modules which are already loaded in the parent process.

This also gives ENV{TAIL} support to all tests which support
daemons which log to stdout/stderr.

4 years agodaemon: avoid race when quitting workers
Eric Wong [Sun, 24 Nov 2019 00:22:30 +0000 (00:22 +0000)]
daemon: avoid race when quitting workers

While the master process has a self-pipe to avoid missing
signals, worker processes lack that aside from a pipe to
detect master death.

That pipe doesn't exist when there's no master process,
so it's possible DS::close never finishes because it
never woke up from epoll_wait.  So create a pipe on
the worker_quit signal and force it into epoll/kevent
so it wakes up right away.

4 years agodaemon: use sigprocmask when respawning workers
Eric Wong [Sun, 24 Nov 2019 00:22:29 +0000 (00:22 +0000)]
daemon: use sigprocmask when respawning workers

We need to block signals in workers during respawns
until they're ready to receive signals.

4 years agodaemon: use sigprocmask to block signals at startup
Eric Wong [Sun, 24 Nov 2019 00:22:28 +0000 (00:22 +0000)]
daemon: use sigprocmask to block signals at startup

`$SIG{FOO} = "IGNORE"' will cause the daemon to miss signals
entirely.  Instead, we can use sigprocmask to block signal
delivery until we have our signal handlers setup.  This closes a
race where a PID file can be written for an init script and a
signal to be dropped via "IGNORE".

4 years ago.gitignore: ignore local prove(1) files
Eric Wong [Sun, 24 Nov 2019 00:22:27 +0000 (00:22 +0000)]
.gitignore: ignore local prove(1) files

As described in prove(1), .prove is storage for --state=save
and .proverc allows per-worktree customizations.

4 years agot/nntpd-tls: sometimes SSL_connect succeeds quickly
Eric Wong [Sun, 24 Nov 2019 00:22:26 +0000 (00:22 +0000)]
t/nntpd-tls: sometimes SSL_connect succeeds quickly

It seems caching can happen within OpenSSL or negotiation
can be delayed in some cases.  In any case, don't barf on
PublicInbox::TLS::epollbit() when connect_SSL succeeds
unexpectedly.

4 years agot/httpd-corner: wait for worker process death
Eric Wong [Sun, 24 Nov 2019 00:22:25 +0000 (00:22 +0000)]
t/httpd-corner: wait for worker process death

We need to ensure the worker process is terminated before
starting a new connection, so leave a persistent HTTP/1.1
connection open and wait for the SIGKILL to take effect
and drop the client.

4 years agot/xcpdb-reshard: test xcpdb --compact
Eric Wong [Sun, 24 Nov 2019 00:22:24 +0000 (00:22 +0000)]
t/xcpdb-reshard: test xcpdb --compact

We did not have a test for this, and need to guard against
regressions when changing Xapcmd to use File::Temp->newdir
in future commits.

4 years agot/v1-add-remove-add: quiet down "git init"
Eric Wong [Sun, 24 Nov 2019 00:22:23 +0000 (00:22 +0000)]
t/v1-add-remove-add: quiet down "git init"

Use the "-q" flag like everywhere else.

4 years agotests: use strict everywhere
Eric Wong [Sun, 24 Nov 2019 00:22:22 +0000 (00:22 +0000)]
tests: use strict everywhere

The "strict" pragma makes code easier to debug, and we had
undeclared variables as a result in t/watch_maildir_v2.t.
So use it everywhere to be consistent with the rest of our
code.