omniti-labs / Net--RabbitMQ

Perl bindings to the librabbitmq-c AMQP library.
Other
25 stars 18 forks source link

Process exit when lost connection #38

Open zpl opened 8 years ago

zpl commented 8 years ago

Hello. there is a bug.

example code:

my $queue = Net::RabbitMQ->new();
$queue->connect( .... );
$queue->channel_open(1);

while (1) {
    my $result = $queue->publish( 1, ... );
    print $result . "\n";
    sleep 1;
}

now, if you shutdown RabbitMQ server, when process inside while - perl process will end right after publish.

try or eval will not help.

That's happened because of write call on closed handle

EPIPE fd is connected to a pipe or socket whose reading end is closed. When this happens the writing process will also receive a SIGPIPE signal. (Thus, the write return value is seen only if the program catches, blocks or ignores this signal.) http://linux.die.net/man/2/write

And because we unable to handle SIGPIPE - our program is closed.

zpl commented 8 years ago

there is how it will looks like with my fix:

$ perl queue.pl                                                                                                                                                         
0
0
0
0
0
-1
-1
-1
-1