lib/PublicInbox/Daemon.pm | 10 +++++++++- lib/PublicInbox/Listener.pm | 1 - t/common.perl | 7 +++++-- diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index 2b7ac266dfabbccfa83c106c0a114d2f1a446faf..2046a7f5abffd382d8a79f2e7aa2c5ee1d923432 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -155,9 +155,9 @@ my $prev = umask 0000; 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; } } @@ -363,6 +363,14 @@ my @rv = (); 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 { diff --git a/lib/PublicInbox/Listener.pm b/lib/PublicInbox/Listener.pm index 594dabb83e38eacd2b2733c952c205e3ffdc2456..604289343260a54f22790795c20ead9b7d8c85da 100644 --- a/lib/PublicInbox/Listener.pm +++ b/lib/PublicInbox/Listener.pm @@ -16,7 +16,6 @@ my ($class, $s, $cb) = @_; setsockopt($s, SOL_SOCKET, SO_KEEPALIVE, 1); setsockopt($s, IPPROTO_TCP, TCP_NODELAY, 1); # ignore errors on non-TCP listen($s, 1024); - IO::Handle::blocking($s, 0); my $self = fields::new($class); $self->SUPER::new($s, EPOLLIN|EPOLLET|EPOLLEXCLUSIVE); $self->{post_accept} = $cb; diff --git a/t/common.perl b/t/common.perl index 3f05b68a368403d7acecac6b9b83ab0b7a87aa12..91d65c5fa380a41b47420993198a57dfada4bc6d 100644 --- a/t/common.perl +++ b/t/common.perl @@ -24,15 +24,18 @@ ReuseAddr => 1, Proto => 'tcp', Type => Socket::SOCK_STREAM(), Listen => 1024, + Blocking => 0, ) } sub unix_server ($) { - IO::Socket::UNIX->new( + my $s = IO::Socket::UNIX->new( Listen => 1024, Type => Socket::SOCK_STREAM(), Local => $_[0], - ) + ); + $s->blocking(0); + $s; } sub spawn_listener {