From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Subject: [PATCH] httpd: fix SIGHUP by invalidating cache on reload
Date: Tue, 20 Jul 2021 08:58:58 +0000 [thread overview]
Message-ID: <20210720085858.GA21082@dcvr> (raw)
In-Reply-To: <20210719204935.GA31835@dcvr>
Eric Wong <e@80x24.org> wrote:
> I seem to recall HUP having some trouble with -httpd (and less
> so with nntpd/imapd); or at least that's what -daemon(8) manpage
> alludes to...
-------8<-------
Subject: [PATCH] httpd: fix SIGHUP by invalidating cache on reload
Since we require separate PublicInbox::HTTPD instances for each
listen socket address (in order to support {SERVER_<NAME|PORT>}
for PSGI env), the old cache needed to be invalidated on rare
app refreshes.
SIGHUP has always been broken in -httpd (but not -imapd or
-nntpd) due to this cache.
Update the daemon documentation and 5.10.1-ize some bits while
we're in the area.
---
Documentation/public-inbox-daemon.pod | 8 +++++---
script/public-inbox-httpd | 6 ++++--
t/httpd.t | 25 +++++++++++++++++++++++++
3 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/Documentation/public-inbox-daemon.pod b/Documentation/public-inbox-daemon.pod
index ec210efa..f77fc3a9 100644
--- a/Documentation/public-inbox-daemon.pod
+++ b/Documentation/public-inbox-daemon.pod
@@ -5,13 +5,14 @@ public-inbox-daemon - common usage for public-inbox network daemons
=head1 SYNOPSIS
public-inbox-httpd
+ public-inbox-imapd
public-inbox-nntpd
=head1 DESCRIPTION
This manual describes common options and behavior for
public-inbox network daemons. Network daemons for public-inbox
-provide read-only NNTP and HTTP access to public-inboxes. Write
+provide read-only NNTP, IMAP and HTTP access to public-inboxes. Write
access to a public-inbox will never be required to run these.
These daemons are implemented with a common core using
@@ -103,7 +104,7 @@ See L</UPGRADING> below.
=item SIGHUP
Reload config files associated with the process.
-(FIXME: not tested for -httpd, yet)
+(Note: broken for L<public-inbox-httpd(1)> only in E<lt>= 1.6)
=item SIGTTIN
@@ -188,4 +189,5 @@ License: AGPL-3.0+ L<https://www.gnu.org/licenses/agpl-3.0.txt>
=head1 SEE ALSO
-L<public-inbox-httpd(1)>, L<public-inbox-nntpd(1)>
+L<public-inbox-httpd(1)>, L<public-inbox-imapd(1)>,
+L<public-inbox-nntpd(1)>
diff --git a/script/public-inbox-httpd b/script/public-inbox-httpd
index b31b896d..7b0ec560 100755
--- a/script/public-inbox-httpd
+++ b/script/public-inbox-httpd
@@ -4,6 +4,7 @@
#
# Standalone HTTP server for public-inbox.
use strict;
+use v5.10.1;
use PublicInbox::Daemon;
BEGIN {
for (qw(Plack::Builder Plack::Util)) {
@@ -14,7 +15,7 @@ BEGIN {
require PublicInbox::HTTPD;
}
-my %httpds;
+my %httpds; # per-listen-FD mapping for HTTPD->{env}->{SERVER_<NAME|PORT>}
my $app;
my $refresh = sub {
if (@ARGV) {
@@ -37,12 +38,13 @@ my $refresh = sub {
sub { $www->call(@_) };
};
}
+ %httpds = (); # invalidate cache
};
PublicInbox::Daemon::run('0.0.0.0:8080', $refresh,
sub ($$$) { # post_accept
my ($client, $addr, $srv) = @_;
my $fd = fileno($srv);
- my $h = $httpds{$fd} ||= PublicInbox::HTTPD->new($srv, $app);
+ my $h = $httpds{$fd} //= PublicInbox::HTTPD->new($srv, $app);
PublicInbox::HTTP->new($client, $addr, $h),
});
diff --git a/t/httpd.t b/t/httpd.t
index 0354a733..849f61bb 100644
--- a/t/httpd.t
+++ b/t/httpd.t
@@ -32,6 +32,10 @@ Date: Thu, 01 Jan 1970 06:06:06 +0000
nntp
EOF
};
+ my $i2 = create_inbox 'test-2', sub {
+ my ($im, $ibx) = @_;
+ $im->add(eml_load('t/plack-qp.eml')) or xbail '->add';
+ };
local $ENV{HOME} = $home;
my $cmd = [ '-init', $group, $inboxdir, 'http://example.com/', $addr ];
ok(run_script($cmd), 'init ran properly');
@@ -64,6 +68,27 @@ EOF
"$http_pfx/$group", "$tmpdir/dumb.git"),
0, 'clone successful');
+ # test config reload
+ my $cfg = "$home/.public-inbox/config";
+ open my $fh, '>>', $cfg or xbail "open: $!";
+ print $fh <<EOM or xbail "print $!";
+[publicinbox "test-2"]
+ inboxdir = $i2->{inboxdir}
+ address = test-2\@example.com
+ url = https://example.com/test-2
+EOM
+ close $fh or xbail "close $!";
+ $td->kill('HUP') or BAIL_OUT "failed to kill -httpd: $!";
+ tick; # wait for HUP to take effect
+ my $buf = do {
+ my $c2 = tcp_connect($sock);
+ $c2->write("GET /test-2/qp\@example.com/raw HTTP/1.0\r\n\r\n")
+ or xbail "c2 write: $!";
+ local $/;
+ <$c2>
+ };
+ like($buf, qr!\AHTTP/1\.0 200\b!s, 'got 200 after reload for test-2');
+
ok($td->kill, 'killed httpd');
$td->join;
next prev parent reply other threads:[~2021-07-20 8:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-19 20:03 Restarting daemons on config file change Konstantin Ryabitsev
2021-07-19 20:49 ` Eric Wong
2021-07-20 8:58 ` Eric Wong [this message]
2021-07-20 17:00 ` Konstantin Ryabitsev
2021-07-20 20:34 ` Eric Wong
2021-07-20 20:49 ` Konstantin Ryabitsev
2021-07-20 21:07 ` Eric Wong
2021-07-20 21:18 ` Konstantin Ryabitsev
2021-07-21 14:05 ` [PATCH 1/2] extsearch: support publicinbox.*.boost parameter Eric Wong
2021-07-21 14:05 ` [PATCH 2/2] init: allow arbitrary key-values via -c KEY=VALUE Eric Wong
2021-07-25 10:40 ` [PATCH 3/2] init: support git <2.30 for "-c KEY=VALUE" args Eric Wong
2021-07-21 15:32 ` [PATCH 0/2] things to make mirroring easier Konstantin Ryabitsev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210720085858.GA21082@dcvr \
--to=e@80x24.org \
--cc=konstantin@linuxfoundation.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).