Subject: | Reference counting across forks |
Date: | Thu, 3 Jul 2008 13:07:07 +0100 |
To: | bug-BerkeleyDB [...] rt.cpan.org |
From: | Mark Hindley <mark [...] hindley.org.uk> |
Paul,
I have been trying to track down the cause of lots of "environment
reference count went negative" messages in the BerkeleyDB log.
I think reference counting across forks is broken. This is using 0.34,
libdb4.6, all from Debian sid.
I have isolated a test case which is below and triggers the error message
for me. The issue seems to be that both processes try to close the
environment after the fork, even though one does not use the tied hash.
Obviously Berkeley DB handles shouldn't be shared across a fork, but in
this case they aren't.
I tried to untie %db and $dbh in the child, but the message still
persists.
Mark
Test case:
#!/usr/bin/perl
use strict;
use warnings;
use BerkeleyDB;
my $env = new BerkeleyDB::Env
-Home => '/tmp',
-Flags => DB_CREATE | DB_INIT_MPOOL | DB_INIT_CDB,
-ErrFile => *STDERR,
-ErrPrefix => "[$$]"
or die $!;
my $dbh = tie my %db, 'BerkeleyDB::Hash',
-Filename => '/tmp/test.db',
-Flags => DB_CREATE,
-Env => $env
or die $!;
my $pid= fork;
if ($pid) {
# use %db here
print "$$: Parent\n";
}
else {
undef $dbh;
untie %db;
print "$$: Child\n";
}