EV::loop not exiting when all AnyEvent watchers destroyed?
Mark Kidwell
MKidwell at looksmart.net
Fri Aug 21 20:15:44 CEST 2009
Hi,
I have a server program that relies on EV::loop's behavior to return
when there are no active watchers. However when I use AnyEvent::HTTP to
asynchronously fetch URLs, EV::loop never returns, even when it appears
that all work is done - see the sample program that demonstrates this
below. This occurs on Perl 5.10.0 and earlier, running EV 3.8 / AnyEvent
5.111 / AnyEvent::HTTP 1.43, all on x86_64 Linux (2.6.24 kernel, libc
2.7).
I tried debugging this a little to find what watchers were still active.
Thinking that it might be an issue with AnyEvent::Handle, I added
Devel::FindRef::track code in AnyEvent::Handle::destroy which shows that
the read watcher on the handle created by the AnyEvent::HTTP request
somehow has a refcount go from 1 to 2 between the time it's set up in
AnyEvent::Handle::start_read and destroy, but one of those refs is lost:
EV::IO=SCALAR(0x9bd6f0) [refcount 2] is
+- referenced by REF(0x953600) [refcount 1], which is
| not found anywhere I looked :(
This may or may not mean anything, hope it helps.
Below is the program I was using to demonstrate this - it simply takes a
list of URLs on stdin.
Thanks and regards,
Mark Kidwell
#!/usr/bin/env perl
use strict;
use warnings;
use EV;
use AnyEvent;
use AnyEvent::HTTP;
my $w; $w = AnyEvent->io(
fh => \*STDIN,
poll => 'r',
cb => sub {
if (defined(my $in = <STDIN>)) {
chomp $in;
http_get $in, sub {
my ($body, $hdr) = @_;
print "$in : $hdr : " . substr($body, 0, 100) . "\n";
};
}
else {
print STDERR "Done..\n";
undef $w;
}
}
);
EV::loop;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/anyevent/attachments/20090821/30851327/attachment.html>
More information about the anyevent
mailing list