From fd799cf3d3f48f0329b125324db173c9d5e4bddf Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 7 Oct 2023 21:24:05 +0000 Subject: ipc: require fork+SOCK_SEQPACKET for wq_* functions None of the lei internals works properly without forking and sockets. The fallback code increases the potential to accidentally call subs in the wrong process during the teardown phase. We'll still support ipc_do w/o forking for now since it forking doesn't benefit small indexing runs from -mda and such. --- lib/PublicInbox/IPC.pm | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) (limited to 'lib/PublicInbox/IPC.pm') diff --git a/lib/PublicInbox/IPC.pm b/lib/PublicInbox/IPC.pm index 068c5623..ba8b5739 100644 --- a/lib/PublicInbox/IPC.pm +++ b/lib/PublicInbox/IPC.pm @@ -256,16 +256,12 @@ sub do_sock_stream { # via wq_io_do, for big requests sub wq_broadcast { my ($self, $sub, @args) = @_; - if (my $wkr = $self->{-wq_workers}) { - my $buf = ipc_freeze([$sub, @args]); - for my $bcast1 (values %$wkr) { - my $sock = $bcast1 // $self->{-wq_s1} // next; - send($sock, $buf, 0) // croak "send: $!"; - # XXX shouldn't have to deal with EMSGSIZE here... - } - } else { - eval { $self->$sub(@args) }; - warn "wq_broadcast: $@" if $@; + my $wkr = $self->{-wq_workers} or Carp::confess('no -wq_workers'); + my $buf = ipc_freeze([$sub, @args]); + for my $bcast1 (values %$wkr) { + my $sock = $bcast1 // $self->{-wq_s1} // next; + send($sock, $buf, 0) // croak "send: $!"; + # XXX shouldn't have to deal with EMSGSIZE here... } } @@ -291,24 +287,17 @@ sub stream_in_full ($$$) { sub wq_io_do { # always async my ($self, $sub, $ios, @args) = @_; - if (my $s1 = $self->{-wq_s1}) { # run in worker - my $fds = [ map { fileno($_) } @$ios ]; - my $buf = ipc_freeze([$sub, @args]); - if (length($buf) > $MY_MAX_ARG_STRLEN) { - stream_in_full($s1, $fds, $buf); - } else { - my $n = $send_cmd->($s1, $fds, $buf, 0); - return if defined($n); # likely - $!{ETOOMANYREFS} and - croak "sendmsg: $! (check RLIMIT_NOFILE)"; - $!{EMSGSIZE} ? stream_in_full($s1, $fds, $buf) : - croak("sendmsg: $!"); - } + my $s1 = $self->{-wq_s1} or Carp::confess('no -wq_s1'); + my $fds = [ map { fileno($_) } @$ios ]; + my $buf = ipc_freeze([$sub, @args]); + if (length($buf) > $MY_MAX_ARG_STRLEN) { + stream_in_full($s1, $fds, $buf); } else { - @$self{0..$#$ios} = @$ios; - eval { $self->$sub(@args) }; - warn "wq_io_do: $@" if $@; - delete @$self{0..$#$ios}; # don't close + my $n = $send_cmd->($s1, $fds, $buf, 0); + return if defined($n); # likely + $!{ETOOMANYREFS} and croak "sendmsg: $! (check RLIMIT_NOFILE)"; + $!{EMSGSIZE} ? stream_in_full($s1, $fds, $buf) : + croak("sendmsg: $!"); } } -- cgit v1.2.3-24-ge0c7