Circumstances in which die () does not exit the Perl script?

I am debugging a really strange problem with a long term Perl script.

The problem is that the script does not exit die() as expected. Instead, the script just hangs without returning.

I did not define any error handlers, so I would suggest that die() will lead to the script terminating immediately.

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 for this behavior? Are any of the modules used to install error handlers that could explain the script hanging on die() ?

+6
source share
1 answer

Well, END blocks and object destructors are still called after die . If one of them freezes (or does something that takes a lot of time), the script will not exit immediately. But this should happen after printing the message from die (unless STDERR is buffered, so you do not see the message immediately).

You mentioned DBI, so you probably have a database descriptor that calls the destructor. (I'm not sure what the problem is though.)

+4
source

Source: https://habr.com/ru/post/892715/


All Articles