]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
ipc: use read_all to deal with short reads
authorEric Wong <e@80x24.org>
Thu, 4 Sep 2025 19:22:25 +0000 (19:22 +0000)
committerEric Wong <e@80x24.org>
Sat, 6 Sep 2025 18:36:01 +0000 (18:36 +0000)
The `read' perlop can still return short reads with the default
IO layer on pipes.

lib/PublicInbox/IPC.pm

index f4d83430e8ae472a1ae1774e265ce620869df414..b744b1aaab2740ec2c8ae1f6f7c1e20a72ece0b5 100644 (file)
@@ -14,7 +14,7 @@ use autodie qw(close pipe read send socketpair);
 use Errno qw(EAGAIN EINTR);
 use Carp qw(croak);
 use PublicInbox::DS qw(awaitpid);
-use PublicInbox::IO;
+use PublicInbox::IO qw(read_all);
 use PublicInbox::Spawn;
 use PublicInbox::OnDestroy;
 use PublicInbox::WQWorker;
@@ -58,8 +58,8 @@ sub _get_rec ($) {
        my ($r) = @_;
        my $len = <$r> // return;
        chop($len) eq "\n" or croak "no LF byte in $len";
-       my $n = read($r, my $buf, $len);
-       $n == $len or croak "short read: $n != $len";
+       my $buf = read_all $r, $len;
+       length($buf) == $len or croak "short read: ",length($buf)," != $len";
        ipc_thaw($buf);
 }