]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Daemon.pm
Merge remote-tracking branch 'origin/nntp'
[public-inbox.git] / lib / PublicInbox / Daemon.pm
index cf011a2020b560d544766021435b822d4e32ff21..2046a7f5abffd382d8a79f2e7aa2c5ee1d923432 100644 (file)
@@ -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 {
@@ -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;