user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 1/2] daemon: shorten lifetime of listener_names mapping
  2019-12-15 23:11  6% [PATCH 0/2] daemon: kill listener early at shutdown Eric Wong
@ 2019-12-15 23:11  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2019-12-15 23:11 UTC (permalink / raw)
  To: meta

Keeping a ref to the IO::Socket handle was preventing
close(2) from being invoked on graceful shutdown of
worker.
---
 lib/PublicInbox/Daemon.pm | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index dd9e7780..842ff1cc 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -25,7 +25,6 @@ my (@cfg_listen, $stdout, $stderr, $group, $user, $pid_file, $daemonize);
 my $worker_processes = 1;
 my @listeners;
 my %pids;
-my %listener_names; # sockname => IO::Handle
 my %tls_opt; # scheme://sockname => args for IO::Socket::SSL->start_SSL
 my $reexec_pid;
 my ($uid, $gid);
@@ -77,6 +76,7 @@ sub sig_setmask { sigprocmask(SIG_SETMASK, @_) or die "sigprocmask: $!" }
 
 sub daemon_prepare ($) {
 	my ($default_listen) = @_;
+	my $listener_names = {}; # sockname => IO::Handle
 	$oldset = POSIX::SigSet->new();
 	$newset = POSIX::SigSet->new();
 	$newset->fillset or die "fillset: $!";
@@ -99,11 +99,11 @@ sub daemon_prepare ($) {
 	if (defined $pid_file && $pid_file =~ /\.oldbin\z/) {
 		die "--pid-file cannot end with '.oldbin'\n";
 	}
-	@listeners = inherit();
+	@listeners = inherit($listener_names);
 
 	# allow socket-activation users to set certs once and not
 	# have to configure each socket:
-	my @inherited_names = keys(%listener_names) if defined($default_cert);
+	my @inherited_names = keys(%$listener_names) if defined($default_cert);
 
 	# ignore daemonize when inheriting
 	$daemonize = undef if scalar @listeners;
@@ -128,7 +128,7 @@ sub daemon_prepare ($) {
 		}
 		# TODO: use scheme to load either NNTP.pm or HTTP.pm
 
-		next if $listener_names{$l}; # already inherited
+		next if $listener_names->{$l}; # already inherited
 		my (%o, $sock_pkg);
 		if (index($l, '/') == 0) {
 			$sock_pkg = 'IO::Socket::UNIX';
@@ -159,7 +159,7 @@ sub daemon_prepare ($) {
 		warn "error binding $l: $! ($@)\n" unless $s;
 		umask $prev;
 		if ($s) {
-			$listener_names{sockname($s)} = $s;
+			$listener_names->{sockname($s)} = $s;
 			$s->blocking(0);
 			push @listeners, $s;
 		}
@@ -353,7 +353,8 @@ sub host_with_port ($) {
 	$@ ? ('127.0.0.1', 0) : ($host, $port);
 }
 
-sub inherit () {
+sub inherit ($) {
+	my ($listener_names) = @_;
 	return () if ($ENV{LISTEN_PID} || 0) != $$;
 	my $fds = $ENV{LISTEN_FDS} or return ();
 	my $end = $fds + 2; # LISTEN_FDS_START - 1
@@ -369,7 +370,7 @@ Set 'NonBlocking = true' in the systemd.service unit to avoid stalled
 processes when multiple service instances start.
 
 			}
-			$listener_names{$k} = $s;
+			$listener_names->{$k} = $s;
 			push @rv, $s;
 		} else {
 			warn "failed to inherit fd=$fd (LISTEN_FDS=$fds)";

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/2] daemon: kill listener early at shutdown
@ 2019-12-15 23:11  6% Eric Wong
  2019-12-15 23:11  7% ` [PATCH 1/2] daemon: shorten lifetime of listener_names mapping Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2019-12-15 23:11 UTC (permalink / raw)
  To: meta

Not everybody uses systemd (or similar) which allow socket
activation.  So we now get rid of listeners ASAP during graceful
shutdown to ensure replacement processes can bind to the same
listen socket w/o requiring SO_REUSEPORT.

Eric Wong (2):
  daemon: shorten lifetime of listener_names mapping
  daemon: drop listeners early in master on graceful shutdown

 lib/PublicInbox/Daemon.pm | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)


^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2019-12-15 23:11  6% [PATCH 0/2] daemon: kill listener early at shutdown Eric Wong
2019-12-15 23:11  7% ` [PATCH 1/2] daemon: shorten lifetime of listener_names mapping Eric Wong

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).