X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FDaemon.pm;h=b3743f5c3ddf80d608c7becf4bc48d242f04eb88;hb=9bd675d33ad1e49bd2ebe12a1d216216e61380de;hp=cf011a2020b560d544766021435b822d4e32ff21;hpb=fbcd2b5eb401a8e1811d803cef9b1c156acb50f6;p=public-inbox.git diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index cf011a20..b3743f5c 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2018 all contributors +# Copyright (C) 2015-2019 all contributors # License: AGPL-3.0+ # contains common daemon code for the nntpd and httpd servers. # This may be used for read-only IMAP server if we decide to implement it. @@ -8,6 +8,7 @@ use warnings; use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/; use IO::Handle; use IO::Socket; +use POSIX qw(WNOHANG); use Socket qw(IPPROTO_TCP SOL_SOCKET); sub SO_ACCEPTFILTER () { 0x1000 } use Cwd qw/abs_path/; @@ -15,7 +16,6 @@ STDOUT->autoflush(1); STDERR->autoflush(1); use PublicInbox::DS qw(now); require PublicInbox::EvCleanup; -require POSIX; require PublicInbox::Listener; require PublicInbox::ParentPipe; my @CMD; @@ -155,9 +155,9 @@ sub daemon_prepare ($) { my $s = eval { $sock_pkg->new(%o) }; warn "error binding $l: $! ($@)\n" unless $s; umask $prev; - if ($s) { $listener_names{sockname($s)} = $s; + $s->blocking(0); push @listeners, $s; } } @@ -252,13 +252,11 @@ sub daemonize () { sub worker_quit { - my ($reason) = @_; # killing again terminates immediately: exit unless @listeners; $_->close foreach @listeners; # call PublicInbox::DS::close @listeners = (); - $reason->close if ref($reason) eq 'PublicInbox::ParentPipe'; my $proc_name; my $warn = 0; @@ -365,6 +363,14 @@ sub inherit () { foreach my $fd (3..$end) { my $s = IO::Handle->new_from_fd($fd, 'r'); if (my $k = sockname($s)) { + if ($s->blocking) { + $s->blocking(0); + warn <<""; +Inherited socket (fd=$fd) is blocking, making it non-blocking. +Set 'NonBlocking = true' in the systemd.service unit to avoid stalled +processes when multiple service instances start. + + } $listener_names{$k} = $s; push @rv, $s; } else { @@ -431,7 +437,7 @@ sub upgrade_aborted ($) { sub reap_children () { while (1) { - my $p = waitpid(-1, &POSIX::WNOHANG) or return; + my $p = waitpid(-1, WNOHANG) or return; if (defined $reexec_pid && $p == $reexec_pid) { upgrade_aborted($p); } elsif (defined(my $id = delete $pids{$p})) { @@ -590,7 +596,7 @@ sub daemon_loop ($$$$) { } else { reopen_logs(); $set_user->() if $set_user; - $SIG{USR2} = sub { worker_quit('USR2') if upgrade() }; + $SIG{USR2} = sub { worker_quit() if upgrade() }; $refresh->(); } $uid = $gid = undef;