A stable, web-based, single-threaded/process, perl application running in production started throwing this error intermittently and only under heavy system load. We can't identify the root cause.
Usage: DBD::Pg::db::DESTROY(dbh) during global destruction
Can anyone offer any explanation of this error? It appears to be thrown from Pg.sx when DESTROY is called without an argument (self?) when Perl is cleaning up before shutting down. (I see that message in older source code via google, but not in our version.) Our environment:
Here is a shot in the dark.
DBI database handles are usually destroyed just like any other object - when nothing references them. However, things can prevent the handle from being destroyed naturally:
When this happens, the object is destroyed as part of 'global destruction' which basically just undefs everything and calls DESTROY in, practically, a random order. This may be what is causing your spurious errors.
To begin with, you can try enumerating your DB handles at the start and end of your script and see if any are still in use by the end. See this code snippet:
sub show_child_handles {
my ($h, $level) = @_;
printf "%sh %s %s\n", $h->{Type}, "\t" x $level, $h;
show_child_handles($_, $level + 1)
for (grep { defined } @{$h->{ChildHandles}});
}
my %drivers = DBI->installed_drivers();
show_child_handles($_, 0) for (values %drivers);
If you're not sure why the object is still in use, you can use Devel::Cycle on some big data structures to find them.
You may also find DBI's tracing functionality useful. Export DBI_TRACE=2 before running your script and it'll log every time a handle is created or destroyed.
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