about summary refs log tree commit homepage
path: root/lib/PublicInbox/CmdIPC4.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-10-23 21:53:46 +0000
committerEric Wong <e@80x24.org>2021-10-23 23:43:10 +0000
commit9a7c75b64e9dc351fddce61b32694d504c2e80c2 (patch)
tree95c241b4401ed7c38d479a46a1ceb0ac1b5e1529 /lib/PublicInbox/CmdIPC4.pm
parent29c85048380d8b7a9cbfd632610740153fccc555 (diff)
downloadpublic-inbox-9a7c75b64e9dc351fddce61b32694d504c2e80c2.tar.gz
I'm seeing ENOBUFS on a RAM-starved system, and slowing the
sender down enough for the receiver to drain the buffers seems
to work.  ENOMEM and ETOOMANYREFS could be in the same boat
as ENOBUFS.

Watching for POLLOUT events via select/poll/epoll_wait doesn't
seem to work, since the kernel can already sleep (or return
EAGAIN) for cases where POLLOUT would work.
Diffstat (limited to 'lib/PublicInbox/CmdIPC4.pm')
-rw-r--r--lib/PublicInbox/CmdIPC4.pm11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/PublicInbox/CmdIPC4.pm b/lib/PublicInbox/CmdIPC4.pm
index 74dbf8a1..c3a7f56e 100644
--- a/lib/PublicInbox/CmdIPC4.pm
+++ b/lib/PublicInbox/CmdIPC4.pm
@@ -17,7 +17,16 @@ no warnings 'once';
         my ($sock, $fds, undef, $flags) = @_;
         my $mh = Socket::MsgHdr->new(buf => $_[2]);
         $mh->cmsghdr(SOL_SOCKET, SCM_RIGHTS, pack('i' x scalar(@$fds), @$fds));
-        Socket::MsgHdr::sendmsg($sock, $mh, $flags);
+        my $s;
+        my $try = 0;
+        do {
+                $s = Socket::MsgHdr::sendmsg($sock, $mh, $flags);
+        } while (!defined($s) &&
+                        ($!{ENOBUFS} || $!{ENOMEM} || $!{ETOOMANYREFS}) &&
+                        (++$try < 50) &&
+                        warn "sleeping on sendmsg: $! (#$try)\n" &&
+                        select(undef, undef, undef, 0.1) == 0);
+        $s;
 };
 
 *recv_cmd4 = sub ($$$) {