shogo82148 / Redis-Fast

fast perl binding for Redis database
https://metacpan.org/release/Redis-Fast
Other
25 stars 21 forks source link

sometimes blocks signals #10

Closed vsespb closed 10 years ago

vsespb commented 10 years ago

problem in 0.06 and 0.05

use strict;
use warnings;
use POSIX;
use Redis::Fast;

my $redis = Redis::Fast->new(server => 'localhost:6379');

my @pids;
for (1..30){
  if (my $pid = fork() ) {
    push @pids, $pid;
    print STDERR "STARTED $$\n";
  } else {
    $SIG{INT}=sub{print STDERR "IGNORING INT\n";};
    $SIG{USR2}=sub{print STDERR "CHILD EXIT $$\n"; exit 0};
    while(){
        $redis->blpop("notakey", 10);
    # <>; 
    }
    exit;
  }
}
$SIG{INT}=sub{kill(POSIX::SIGUSR2, @pids)};
while(wait()!=-1){};
print "DONE\n";

to terminate this script I use Ctrl-C. Often (~ 20% cases) I need press Ctrl-C twice to terminate.

but if I replace $redis->blpop("notakey", 10); with <>; (i.e. readline from stdin), Ctrl-C works always. i.e. perl io works well with signals.

this code looks strange, but I reduced it from real code, which just tries to catch SIGUSR (and SIGINT just in case) and kill all child processes.

perl 5.14 from Ubuntu 12.04

also, sometimes segfaults

Attempt to free unreferenced scalar: SV 0x115f0c0, Perl interpreter: 0x113c010 during global destruction.
Attempt to free unreferenced scalar: SV 0x115f0c0, Perl interpreter: 0x113c010 during global destruction.
Attempt to free unreferenced scalar: SV 0x115f0c0, Perl interpreter: 0x113c010 during global destruction.

Reproducible in 0.05, 0.06, 0.08. I tried 0.07 - don't installs. 0.08 - same + crash from issue #9 ), and btw 0.05 was before issue #5.

vsespb commented 10 years ago

maybe related https://rt.perl.org/Ticket/Display.html?id=93428 i.e. use of select() instead of pselect() (however I am not C programmer so not sure)

shogo82148 commented 10 years ago

pr #12 will fix this. try it please.

vsespb commented 10 years ago

LGTM

shogo82148 commented 10 years ago

thx. I merged #12 and released Redis::Fast 0.0.9.