Subject: | Problems with losing connection when forking |
It seems this module suffers from loss of connection when a process
opens a connection, forks and the child exits. This is due to the
DESTROY method getting called on the connection when the child process
exits, even when the parent process still has a reference to the
connection handle. Minimal(ish) example:
my $mq = Net::RabbitMQ->new();
$mq->connect("localhost", { user => "guest", password => "guest" });
$mq->channel_open(1);
my $queue = $mq->queue_declare(1, '', { exclusive => 1 });
$mq->consume(1, $queue, {});
my $pid = fork();
die "Couldn't fork\n" unless defined $pid;
if (! $pid) {
# Child
exit;
}
$mq->recv();
The call to recv() dies with "Bad frame read.", because the connection
has been destroyed when the child exits. This is a problem when writing
a daemon that blocks waiting for a message, then forks to process it.
I would suggest adding something equivalent to DBI's "InvactiveDestroy"
parameter (which is solving the same problem), so that a handle can be
prevented from disconnecting when getting destroyed.
I may have time to patch this at a later date, although any
help/suggestions would be appreciated (I have minimal XS skills).