miyagawa / AnyEvent-Redis

Asynchronous Redis client
http://search.cpan.org/dist/AnyEvent-Redis
41 stars 16 forks source link

clean-up also connect_queue AE::cv-s #28

Open jozef opened 5 years ago

jozef commented 5 years ago

Hi,

cleanup() may leave the AE::cv objects without recv() in connect_queue array resulting in hanging of the async code. Here is a simple code that will never finish:

#!/usr/bin/perl

use AnyEvent::Redis;

my $redis = AnyEvent::Redis->new(
    port => 9999,   # unallocated port
    on_error => sub { warn @_ },
    on_cleanup => sub { warn "Connection closed: @_" },
);

my $cv1 = $redis->get( 'foo1' );
my $cv2 = $redis->get( 'foo2' );
$cv2->recv;

will output:

Can't connect Redis server: Connection refused at ./connect_queue_bug.pl line 7.
Connection closed: Can't connect Redis server: Connection refused at ./connect_queue_bug.pl line 8.

and never finish.

With this patch:

Can't connect Redis server: Connection refused at ./connect_queue_bug.pl line 7.
Connection closed: Can't connect Redis server: Connection refused at ./connect_queue_bug.pl line 8.
Can't connect Redis server: Connection refused at ./connect_queue_bug.pl line 14.

and terminate normally.

Best regards Jozef