Issue with AnyEvent::AIO
Dominik Csapak
d.csapak at proxmox.com
Thu Jun 29 15:24:54 CEST 2023
Hi all,
We have an issue with AnyEvent::AIO, basically we don't use it directly, but as
soon as it's installed on a machine, our AnyEvent based daemon (a http-sever basically)
uses 100% cpu time on one core (per forked subprocess).
I have created a small reproducer:
(sorry for the ugly code)
---8<---
#!/usr/bin/env perl
use strict;
use warnings;
use AnyEvent::IO;
use IO::Socket::IP;
use Socket qw(SOMAXCONN);
use POSIX ":sys_wait_h";
my $condvar = AnyEvent->condvar;
my $socket = IO::Socket::IP->new( LocalHost => "::", (
LocalPort => 8888,
Listen => SOMAXCONN,
Proto => 'tcp',
GetAddrInfoFlags => 0,
ReuseAddr => 1,
));
my $child_list = [];
sub fork_child {
print "forking\n";
if (my $child = fork()) {
push @$child_list, $child;
return 0;
} else {
return 1;
}
}
while (scalar(@$child_list) < 2) {
if (fork_child()) {
last;
}
}
if (scalar(@$child_list)) {
while (1) {
print "waiting\n";
my $ret = waitpid(-1, WNOHANG);
if ($ret < 0) {
exit;
}
sleep 1;
}
}
my $sw = AnyEvent->io(fh => $socket, poll => 'r', cb => sub {
warn "conn";
$socket->accept();
});
$condvar->recv();
--->8---
We use Debian (currently 12/Bookworm) as our base and installing the package
'libanyevent-aio-perl' and restarting the daemons is enough to trigger it.
Without the package installed it behaves normally.
When using the part from perldoc:
---8<---
undef $AnyEvent::AIO::WATCHER;
--->8---
it also prevents this behavior (and the page says to report if it's necessary).
Any Idea what we might do wrong here?
The real code handles the accepted connections/saves/replies/etc. ofc,
but for the reproducer this was enough.
(also bear with me, I'm not super deep into AnyEvent ;) )
Thanks
Kind Regards
Dominik
More information about the anyevent
mailing list