Open mbeijen opened 6 years ago
Hi,
I located the leak to DBI driver hash ChildHandles array:
DB<16> x $drh
0 DBI::dr=HASH(0x7faa1f5152f8)
'Attribution' => 'DBD::mysql by Patrick Galbraith'
'ChildHandles' => ARRAY(0x7faa1ea3c278)
0 undef
1 undef
2 undef
3 DBI::db=HASH(0x7faa1ea6a730)
empty hash
'Err' => SCALAR(0x7faa20024a18)
-> undef
'Errstr' => SCALAR(0x7faa20024af0)
-> undef
'FetchHashKeyName' => 'NAME'
'ImplementorClass' => 'DBD::mysql::dr'
'Name' => 'mysql'
'State' => SCALAR(0x7faa1f59c2c0)
-> undef
'TraceLevel' => 0
'Version' => 4.035
DB<17>
the array grows every time a new connection is made as old connection handles left there undef values.
A workaround by clearing the array after undeffing a connection handle fixes the leak:
$dbh = DBI->connect("DBI:mysql:database=radiator;host=localhost;port=3306", "root", "",
{'RaiseError' => 1});
%{$dbi_drivers} = DBI->installed_drivers() unless defined $dbi_drivers;
...
$dbh->disconnect();
undef $dbh;
@{$dbi_drivers->{mysql}->{ChildHandles}} = grep defined, @{$dbi_drivers->{mysql}->{ChildHandles}};
DBI's documentation states following:
https://metacpan.org/pod/DBI#ChildHandles
The ChildHandles attribute contains a reference to an array of all the handles created by this handle which are still accessible. The contents of the array are weak-refs and will become undef when the handle goes out of scope. (They're cleared out occasionally.)
ChildHandles returns undef if your perl version does not support weak references (check the Scalar::Util module). The referenced array returned should be treated as read-only.
and according to the code, cleaning is done every 120 handles
any chance to use DBD::mysql with MariaDB 10.2 ?
Thank you
@graz68a There is DBD::MariaDB https://metacpan.org/release/PALI/DBD-MariaDB-0.90_01 with support for MariaDB 10.2
Migrated from rt.cpan.org#80669 (status was 'open')
Requestors:
From sveta.smirnova@oracle.com on 2012-11-06 20:06:50:
From michielb@cpan.org on 2016-12-01 08:33:20:
From pali@cpan.org on 2017-01-13 22:03:21: