I'm debugging a really weird problem with a long-running Perl script.
The problem is that the script does not exit on die()
as expected. Instead the script just hangs without returning.
I've not defined any error handlers myself so I would assume that die()
would lead to an immediate termination of the script.
This is the basic structure of the script and the modules used:
#!/usr/bin/perl
use strict;
use utf8;
use warnings;
use DBI; # with MySQL driver ("dbi:mysql:database=...")
use Geo::IP;
use POSIX;
use URI::Escape;
open(COMMAND, 'command_line |');
while (<COMMAND>) {
#
# .. stuff that can go wrong ..
#
die("I'm expecting the script to terminate here. It doesn't.") if ($gone_wrong);
}
close(COMMAND);
What could be the explanation to this behaviour? Is any of the modules used known to set up error handlers that could explain the script hanging on die()
?
The die() function can be used to stop the script and can be used to display a message to the end user. It can be used at the right side of the OR ( || ) operator and at left side can be any expression like the eval() function.
Well, END
blocks and object destructors are still called after a die
. If one of those hangs (or does something that takes a long time), the script won't exit immediately. But that should happen after printing the message from die
(unless STDERR is buffered so you don't see the message immediately).
You mention DBI, so you probably have a database handle whose destructor is being called. (I'm not sure that's the problem, though.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With