Invalid "recursive invocation" with Coro::Handle + eval
Harry Mason
harry.mason at smoothwall.net
Thu Oct 15 13:28:18 CEST 2015
This code seems to trigger an internal error somewhere in either
Coro, Coro::EV, or libev. Am I doing something wrong, or is there a bug?
I appreciate you can't use the same Coro::Handle instance simultaneously
from two coroutines, but here only one coroutine is using it.
This is a simplified test case. The use of throw() is desired for other
reasons; I know there are other possible approaches in this example.
If nothing is entered on stdin, we expect $line1 to be
"interrupted reading first line: interrupt\n"
but also $line2 ends up as
"interrupted reading next line: recursive invocation of readable_ev or
writable_ev (concurrent Coro::Handle calls on same handle?), detected
at /usr/lib/perl5/Coro/Handle.pm line 551.\n"
I am also seeing my program's main EV::loop croak with the message
"Coro::State object required". It seems to have a similar cause but it
is hard to pin down.
Cheers
Harry
--- 8< ---
#!/usr/bin/perl
use 5.14.0;
use warnings;
use Coro;
use EV;
use AnyEvent;
use Coro::AnyEvent;
use Coro::Handle;
my $line1;
my $line2;
my $worker = async {
my $fh = unblock \*STDIN;
eval {
$line1 = $fh->readline;
};
if ($@) {
$line1 = "interrupted reading first line: $@";
}
eval {
$line2 = $fh->readline;
};
if ($@) {
$line2 = "interrupted reading next line: $@";
}
};
Coro::AnyEvent::sleep(1);
$worker->throw("interrupt\n");
$worker->ready;
$worker->join;
print $line1, $line2;
More information about the anyevent
mailing list