Awaiting a bugfix
When using Proc::Async
we need to await
while waiting for a fix for R#3817. While adding many tests to Shell::Piping I got a flapper on Travis. After my last misadvanture while testing async code I learned to use stress -c 30
to make sure that OS threads are congested. And sure enough, I got the same tests to fail then on Travis. A workaround is to await
after reading form Proc::Async.stdout
. In my code that looks like the following.
for $.proc-out-stdout.lines {
my $value := &.code.($_);
my $processed = $value === Nil ?? ‚‘ !! $value ~ "\n";
await $.proc-in.write: $processed.encode with $.proc-in;
# ^^^^^ WORKAROUND for R#3817
}
I then had to add a piece of odd code at another place to have something to await
on.
method write($blob) { my $p = Promise.new; $p.keep; a.push: $blob.decode.chomp; $p }
The Promise
is really just there so we can nudge Rakudo to have a good look at its threads. If you are using Proc::Async
in your code please check for .write
and test it on a system with more work then cores. You wont get an error with this bug. It will just silently drop values that are send via .write
to another process or fetched via .stdout.lines
. Good hunting!
-
July 27, 2020 at 22:472020.30 Almost On Time – Rakudo Weekly News