CC: | MFROST [...] cpan.org, frajulac [...] contre.com, yanick [...] cpan.org |
Subject: | `import_keys` forks too many processes and changes loop behaviour |
Hey All,
I noticed that this module dies in case of any error, so stopping our main program. Rather, it should send the error message to the caller and let caller decide what to do.
However, I handled the errors using `eval`. While handling the `import_keys`, I found a nasty bug in it (when filename is passed instead of arrayref). Below is my simplified program.
use GnuPG qw( :algo );
my $gpg = new GnuPG;
for (1..3) {
print "Loop count: $_\n";
eval { $gpg->import_keys( keys => '/home/kamal-pub.ascaaa' ); }; # This is invalid path so as to generate error
if ($@) {
print "Error found: $@\n";
} else {
print "Success.\n";
}
}
======================================
Output: Right now I am printing only loop count to focus on real bug. Please notice, it has executed loop multiple times for the same values, instead of running just 5 times.
Loop count: 1
Loop count: 2
Loop count: 3
Loop count: 4
Loop count: 5
Loop count: 2
Loop count: 3
Loop count: 4
Loop count: 5
Loop count: 5
Loop count: 4
Loop count: 5
Loop count: 5
Loop count: 3
Loop count: 4
Loop count: 5
Loop count: 5
Loop count: 4
Loop count: 5
Loop count: 5
======================================
I tried to debug it but the debugger stops on this eval line saying "
######### Forked, but do not know how to create a new TTY. #########
Since two debuggers fight for the same TTY, input is severely entangled.
I know how to switch the output to a different window in xterms
and OS/2 consoles only. For a manual switch, put the name of the created TTY
in $DB::fork_TTY, or define a function DB::get_fork_TTY() returning this.
On UNIX-like systems one can get the name of a TTY for the given window
by typing tty, and disconnect the shell from TTY by sleep 1000000."
======================================
As far as I could understand, module is forking too many threads of the same program, which leads to quite different behaviour of the loops. However, when I used arrayref as parameter to import_keys, everything seemed fine.