Skip Menu |

This queue is for tickets about the DBD-mysql CPAN distribution.

Report information
The Basics
Id: 86153
Status: resolved
Priority: 0/
Queue: DBD-mysql

People
Owner: CAPTTOFU [...] cpan.org
Requestors: Jeremy [...] Zawodny.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 4.028



Subject: Memory Leak when connecting to a down server...
Date: Fri, 14 Jun 2013 11:54:14 -0700
To: bug-DBD-mysql [...] rt.cpan.org
From: Jeremy Zawodny <Jeremy [...] Zawodny.com>
(This was also filed on github but I'm not clear where the correct place to report it really is.) https://github.com/CaptTofu/DBD-mysql/issues/45 I was making use of the new async features in developing a new module and came across a memory leak during testing. I was able to whittle the test case down to something quite small. The code is here: https://gist.github.com/jzawodn/5784173 and I'll paste it in this bug report too. If you put a valid user/password and host/port combo in the script, it will stay at a fixed memory size. However, if the connection fails for any reason (down host, bad username) the script will grow in memory usage until terminated. #!/usr/bin/perl -w use strict; use warnings; use feature qw(say); use DBD::mysql; my $host = 'dev4h'; my $port = 9307; my $dsn = "DBI:mysql:host=$host;port=$port"; my $user = 'foo'; my $pass = 'bar'; while (1) { my $dbh = DBI->connect($dsn, $user, $pass); if ($dbh) { say "connected to $host:$port"; } else { say "connect fail to $host:$port: $@"; } undef $dbh; } exit; __END__
Ok, time to break out valgrind and see what I can find on this. Also, I am going to see if older versions manifest this behavior. On Fri Jun 14 14:54:26 2013, JZAWODNY wrote: Show quoted text
> (This was also filed on github but I'm not clear where the correct > place to report it really is.) > > https://github.com/CaptTofu/DBD-mysql/issues/45 > > I was making use of the new async features in developing a new module > and came across a memory leak during testing. I was able to whittle > the test case down to something quite small. > > The code is here: https://gist.github.com/jzawodn/5784173 and I'll > paste it in this bug report too. > > If you put a valid user/password and host/port combo in the script, it > will stay at a fixed memory size. However, if the connection fails for > any reason (down host, bad username) the script will grow in memory > usage until terminated. > > #!/usr/bin/perl -w > use strict; > use warnings; > use feature qw(say); > use DBD::mysql; > > my $host = 'dev4h'; > my $port = 9307; > my $dsn = "DBI:mysql:host=$host;port=$port"; > my $user = 'foo'; > my $pass = 'bar'; > > while (1) { > my $dbh = DBI->connect($dsn, $user, $pass); > if ($dbh) { > say "connected to $host:$port"; > } else { > say "connect fail to $host:$port: $@"; > } > undef $dbh; > } > > exit; > __END__
Ok, before I set up Valgrind, I thought I'd give it a quick look. I couldn't remember if mysql_init() allocated anything, but thought I would try some nice housekeeping and free the variable "sock" if the connection failed. Problem went away. Now, I will add a test. Fix is in latest in git. thank you for this bug report Jeremy, and I'm sorry it took me so long to get to it. On Wed Oct 09 11:11:08 2013, CAPTTOFU wrote: Show quoted text
> Ok, time to break out valgrind and see what I can find on this. Also, > I am going to see if older versions manifest this behavior. > > On Fri Jun 14 14:54:26 2013, JZAWODNY wrote:
> > (This was also filed on github but I'm not clear where the correct > > place to report it really is.) > > > > https://github.com/CaptTofu/DBD-mysql/issues/45 > > > > I was making use of the new async features in developing a new module > > and came across a memory leak during testing. I was able to whittle > > the test case down to something quite small. > > > > The code is here: https://gist.github.com/jzawodn/5784173 and I'll > > paste it in this bug report too. > > > > If you put a valid user/password and host/port combo in the script, > > it > > will stay at a fixed memory size. However, if the connection fails > > for > > any reason (down host, bad username) the script will grow in memory > > usage until terminated. > > > > #!/usr/bin/perl -w > > use strict; > > use warnings; > > use feature qw(say); > > use DBD::mysql; > > > > my $host = 'dev4h'; > > my $port = 9307; > > my $dsn = "DBI:mysql:host=$host;port=$port"; > > my $user = 'foo'; > > my $pass = 'bar'; > > > > while (1) { > > my $dbh = DBI->connect($dsn, $user, $pass); > > if ($dbh) { > > say "connected to $host:$port"; > > } else { > > say "connect fail to $host:$port: $@"; > > } > > undef $dbh; > > } > > > > exit; > > __END__
Subject: Re: [rt.cpan.org #86153] Memory Leak when connecting to a down server...
Date: Thu, 10 Oct 2013 20:34:44 -0700
To: bug-DBD-mysql [...] rt.cpan.org
From: Jeremy Zawodny <Jeremy [...] Zawodny.com>
Awesome, thanks for the fix! Jeremy On Thu, Oct 10, 2013 at 8:16 PM, Patrick Galbraith via RT < bug-DBD-mysql@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=86153 > > > Ok, before I set up Valgrind, I thought I'd give it a quick look. I > couldn't remember if mysql_init() allocated anything, but thought I would > try some nice housekeeping and free the variable "sock" if the connection > failed. Problem went away. > > Now, I will add a test. Fix is in latest in git. > > thank you for this bug report Jeremy, and I'm sorry it took me so long to > get to it. > > On Wed Oct 09 11:11:08 2013, CAPTTOFU wrote:
> > Ok, time to break out valgrind and see what I can find on this. Also, > > I am going to see if older versions manifest this behavior. > > > > On Fri Jun 14 14:54:26 2013, JZAWODNY wrote:
> > > (This was also filed on github but I'm not clear where the correct > > > place to report it really is.) > > > > > > https://github.com/CaptTofu/DBD-mysql/issues/45 > > > > > > I was making use of the new async features in developing a new module > > > and came across a memory leak during testing. I was able to whittle > > > the test case down to something quite small. > > > > > > The code is here: https://gist.github.com/jzawodn/5784173 and I'll > > > paste it in this bug report too. > > > > > > If you put a valid user/password and host/port combo in the script, > > > it > > > will stay at a fixed memory size. However, if the connection fails > > > for > > > any reason (down host, bad username) the script will grow in memory > > > usage until terminated. > > > > > > #!/usr/bin/perl -w > > > use strict; > > > use warnings; > > > use feature qw(say); > > > use DBD::mysql; > > > > > > my $host = 'dev4h'; > > > my $port = 9307; > > > my $dsn = "DBI:mysql:host=$host;port=$port"; > > > my $user = 'foo'; > > > my $pass = 'bar'; > > > > > > while (1) { > > > my $dbh = DBI->connect($dsn, $user, $pass); > > > if ($dbh) { > > > say "connected to $host:$port"; > > > } else { > > > say "connect fail to $host:$port: $@"; > > > } > > > undef $dbh; > > > } > > > > > > exit; > > > __END__
> > > >
This broke error handling, it accesses freed memory when reporting the error with mysql_dr_error. See RT #97625 The free needs to happens later with imp_dbh->pmysql. On Thu Oct 10 23:34:58 2013, JZAWODNY wrote: Show quoted text
> Awesome, thanks for the fix! > > Jeremy > > On Thu, Oct 10, 2013 at 8:16 PM, Patrick Galbraith via RT < > bug-DBD-mysql@rt.cpan.org> wrote: >
> > <URL: https://rt.cpan.org/Ticket/Display.html?id=86153 > > > > > Ok, before I set up Valgrind, I thought I'd give it a quick look. I > > couldn't remember if mysql_init() allocated anything, but thought I would > > try some nice housekeeping and free the variable "sock" if the connection > > failed. Problem went away. > > > > Now, I will add a test. Fix is in latest in git. > > > > thank you for this bug report Jeremy, and I'm sorry it took me so long to > > get to it. > > > > On Wed Oct 09 11:11:08 2013, CAPTTOFU wrote:
> > > Ok, time to break out valgrind and see what I can find on this. Also, > > > I am going to see if older versions manifest this behavior. > > > > > > On Fri Jun 14 14:54:26 2013, JZAWODNY wrote:
> > > > (This was also filed on github but I'm not clear where the correct > > > > place to report it really is.) > > > > > > > > https://github.com/CaptTofu/DBD-mysql/issues/45 > > > > > > > > I was making use of the new async features in developing a new module > > > > and came across a memory leak during testing. I was able to whittle > > > > the test case down to something quite small. > > > > > > > > The code is here: https://gist.github.com/jzawodn/5784173 and I'll > > > > paste it in this bug report too. > > > > > > > > If you put a valid user/password and host/port combo in the script, > > > > it > > > > will stay at a fixed memory size. However, if the connection fails > > > > for > > > > any reason (down host, bad username) the script will grow in memory > > > > usage until terminated. > > > > > > > > #!/usr/bin/perl -w > > > > use strict; > > > > use warnings; > > > > use feature qw(say); > > > > use DBD::mysql; > > > > > > > > my $host = 'dev4h'; > > > > my $port = 9307; > > > > my $dsn = "DBI:mysql:host=$host;port=$port"; > > > > my $user = 'foo'; > > > > my $pass = 'bar'; > > > > > > > > while (1) { > > > > my $dbh = DBI->connect($dsn, $user, $pass); > > > > if ($dbh) { > > > > say "connected to $host:$port"; > > > > } else { > > > > say "connect fail to $host:$port: $@"; > > > > } > > > > undef $dbh; > > > > } > > > > > > > > exit; > > > > __END__
> > > > > > > >
-- Reini Urban
Thanks all. This was fixed in version 4.028.