# New Ticket Created by  Sam S. 
# Please include the string:  [perl #129882]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=129882 >


The following code attempts to pipe a large Blob (larger than a pipe's
buffer size) through an external command.
However, it hangs on the `.in.close` line and never finishes:

    my $proc = run «cat -», :in, :out, :bin;
    my $input = ("a" x 1000000).encode;
    my $promise = start {
        $proc.in.write: $input;
        $proc.in.close;
    }
    say $proc.out.slurp-rest(:close, :bin).bytes;
    await $promise;

More verbose version of the code with debug output showing where it blocks:
https://gist.github.com/smls/75518c746ca65b3287482c491971eac0

IRC comments:

  <timotimo>   moar sometimes gets confused, i think
  <timotimo>   or maybe it's libuv

  <RabidGravy> shouldn't that give an error as other handles across threads do?

  <gfldex>     you get the same behaviour with
               https://rt.perl.org/Public/Bug/Display.html?id=129787

Note that without the `start` (i.e. when writing to `.in` and then
reading from `.out` in the same thread), it already hangs on the
`.in.write`, as geekosaur explains:

  <geekosaur> it will block if the process is not reading, yes. pipes have
              finite buffer space
  <geekosaur> whether this block is happening at OS level or if libuv is
              supposed to be using non-blocking operations and return a "would
              block, try again" and some higher level is blocking based on
              that, I cannot say

Reply via email to