Skip to content

Commit d76d342

Browse files
committed
Do not push to array asynchronously
It was clear right from the start that doing so is stupid, but turns out it causes actual segfaults (RT #128870). There is a chance that this was the reason behind some of the segfaults observed during the testing of Perl 6 bots. We will see.
1 parent 5296253 commit d76d342

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Whateverable.pm6

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@ multi method irc-privmsg-me($msg) {
5656
method help($message) { See {SOURCE} } # override this in your bot
5757

5858
method get-output(*@run-args, :$timeout = $!timeout) {
59-
# TODO is the whole async stuff here sane? I don't think so…
60-
my @out;
59+
my $out = Channel.new; # TODO switch to some Proc :merge thing once it is implemented
6160
my $proc = Proc::Async.new(|@run-args);
62-
$proc.stdout.tap(-> $v { @out.push: $v });
63-
$proc.stderr.tap(-> $v { @out.push: $v });
61+
$proc.stdout.tap(-> $v { $out.send: $v });
62+
$proc.stderr.tap(-> $v { $out.send: $v });
6463

6564
my $s-start = now;
6665
my $promise = $proc.start;
@@ -69,9 +68,10 @@ method get-output(*@run-args, :$timeout = $!timeout) {
6968

7069
if not $promise.status ~~ Kept { # timed out
7170
$proc.kill; # TODO sends HUP, but should kill the process tree instead
72-
@out.unshift: «timed out after $timeout seconds, output»: ;
71+
$out.send: «timed out after $timeout seconds, output»: ;
7372
}
74-
return (@out.join.chomp, $promise.result.exitcode, $promise.result.signal, $s-end - $s-start)
73+
$out.close;
74+
return ($out.list.join.chomp, $promise.result.exitcode, $promise.result.signal, $s-end - $s-start)
7575
}
7676

7777
method to-full-commit($commit) {

0 commit comments

Comments
 (0)