Subject: | AsyncAwait and LibXML |
Date: | Sun, 17 Sep 2017 09:10:53 +0200 |
To: | bug-Future-AsyncAwait [...] rt.cpan.org |
From: | "Týnovský, Miroslav" <tynovsky [...] avast.com> |
Hi,
First of all, thanks for all the great work. I discovered a strange (buggy)
behaviour when using Future::AsyncAwait together with XML::LibXML.
Particularly, my program exits with error code 0 in the middle of execution.
I'm using:
Future::AsyncAwait 0.10
XML::LibXML 2.0128
perl v5.24.0
Steps to reproduce:
1. Run the following program
#!/usr/bin/env perl
use strict;
use warnings;
use XML::LibXML;
use IO::Async::Timer::Periodic;
use IO::Async::Loop;
use Future::AsyncAwait;
use Test::More;
my @futures;
my $loop = IO::Async::Loop->new;
run();
my $timer = IO::Async::Timer::Periodic->new(
interval => 1,
on_tick => sub {
while (my $f = shift @futures) {
$f->done(1)
}
},
);
$loop->add($timer);
$timer->start();
$loop->run();
async sub run {
await f1();
print "f1\n";
await f2();
print "f2\n";
$loop->stop();
pass();
done_testing();
}
async sub f1 {
await new_future();
my $return = 1;
return $return
}
sub f2 {
return new_future();
}
sub new_future {
# XML::LibXML->load_xml(string => '<a />');
my $f = $loop->new_future();
push @futures, $f;
return $f
}
You should see the following output:
f1
f2
ok 1
1..1
2. Now uncomment the line which is commented out
XML::LibXML->load_xml(string => '<a />');
and execute again.
Now the output is incomplete - part of the program didn't get executed:
f1
And the program still exited with exitcode 0.
3. Execute again with environment PERL_FUTURE_DEBUG=1 set. It works
properly again.
4. Also note that f1 needs to contain await in order to reproduce the bug.
I have no guess about the cause. Let me know if I can provide any more
details you potentially need.
Thank you,
Miroslav