Subject: | can't safe break() a loop on network error |
Date: | Thu, 9 Jul 2020 13:39:32 +1000 |
To: | bug-Asterisk-AMI [...] rt.cpan.org |
From: | Alex 'AdUser' Z <ad_user [...] runbox.com> |
The problem: after receiving network error on socket,
Asterisk AMI calls internal _on_error routine, executes user's
on_error() callback if defined and destroys object itself, ...but keeps
underlying event-loop running. Calling a break() manually in on_error()
callback gives segfault. The only way to break that loop now is call
exit(), because internally used in loop()/break() AnyEvent condvar
reference get lost.
Possible fix is make copy of that reference and send() to it after
Asterisk::AMI object gets destroyed.
---
minimal code:
sub on_error {
my ($ami, $str) = @_;
printf "* socket error: %s\n", $str;
$ami->break; # <- segfault if uncommented, endless loop otherwise
}
my $ami = Asterisk::AMI->new(
...
Blocking => 0,
Keepalive => 10,
on_error => \&on_error,
);
$ami->loop;
exit 0; # never reached
---
output:
<time passes>
* socket error: Broken pipe
double free or corruption (out)
--
-- Alex