Subject: | Connection dies when forking and no callback |
Hi, first thank you for the module, it is great.
I was trying to fork in a script with a connection to a KVM server. After the forked code exits, the script dies when I try to access the VM again.
I checked the docs and I saw about the close_callback. So I started coding a callback to reconnect. To my surprise I don't have to write any code in there. Only having one registered makes the script not to die.
I am not sure that was the expected behaviour but I guess there must be a bug somwhere. The system is Ubuntu Xenial with Sys::Virt 1.2.16.
Here is a test. Let me know if there is something else I can try.
Subject: | test_fork.t |
#!/usr/bin/perl
use warnings;
use strict;
use Sys::Virt;
use Test::More tests => 2;
my $vm = Sys::Virt->new( address => "qemu:///system" );
#################################################
sub _reconnect { }
sub test_fork {
diag("testing fork");
my $pid = fork();
# son
exit if !$pid;
#parent
wait();
$vm->list_all_domains ;
# it is ok(1) because we just test it gets here
ok(1);
}
#################################################3
# with the callback it forks
$vm->register_close_callback(\&_reconnect);
test_fork();
#only commenting the next line makes test 2 ok
$vm->unregister_close_callback();
test_fork();