Subject: | CORE::exit trashes file handles |
Twig on Linux drops open filehandles via calling END, affecting e.g. DBI
Tested on Linux
Sample program:
use LockFile::Simple;
use XML::Twig;
my $dbh = DBI->connect('....);
my $lockmgr = LockFile::Simple->make(-autoclean=>1, -stale=>1, -hold=>0);
$lockmgr->trylock("/tmp/.".DST) || die "can't lock /tmp/.".DST."\n";
my $t = XML::Twig->new( twig_handlers => { 'mapping' => \&mapme, } );
$t->parseurl(URL);
# HERE parseurl calls CORE::exit
# this triggers a lockfile release.
# it also causes e.g. DBI to drop the connection, invalidating prepared statements
from IRC:
"possibly XML::Twig should be using POSIX::_exit instead, although that won't work on win32"
Parseurl is therefore unusable when using any filelocks that act on END, as the child forked by XML::Twig seems to call the END handlers of all open handlers.
Backtrace:
WARNING: releasing 1 pending lock...
at /usr/share/perl5/Log/Agent/Driver/Default.pm line 140
Log::Agent::Driver::Default::logwarn('Log::Agent::Driver::Default=HASH(0x22649b8)', 'Log::Agent::Message=ARRAY(0x1a19d90)') called at blib/lib/Log/Agent.pm (autosplit into blib/lib/auto/Log/Agent/logwarn.al) line 326
Log::Agent::logwarn(undef) called at /usr/share/perl5/LockFile/Manager.pm line 103
LockFile::Manager::release_all('LockFile::Manager=HASH(0x1a1a0d8)') called at /usr/share/perl5/LockFile/Manager.pm line 110
LockFile::Manager::END() called at /usr/share/perl5/XML/Twig.pm line 1203
eval {...} called at /usr/share/perl5/XML/Twig.pm line 1203