List:MySQL and Perl« Previous MessageNext Message »
From:John Heitmann Date:January 10 2003 6:42pm
Subject:Re: Mem leak upon recovering after a disconnect
View as plain text  
On Friday, January 10, 2003, at 05:07  AM, Jochen Wiedmann wrote:

>
> Zitiere John Heitmann <JHeitmann@stripped>:
>
>> for my $i (1..1000) {
>> 	my $dbh = DBI->connect(...);
>> 	$dbh->disconnect();
>> 	$dbh->do(something);
>> 	sleep(1);
>> }
>
> I do get you right, that the problem is caused because you
> attempt to use a closed connection?

Exactly.

>
>> It is easy to workaround once we found the problem, we just check the
>> Active flag before we do anything. Finding the problem took quite
>> awhile though :-(
>
> By that you mean that you omit using the closed connection?

Right, so here's our current fix (since in our full example we can 
never be sure if 3rd party code has closed the connection):

for my $i (1..1000) {
	my $dbh = DBI->connect(...);
	$dbh->disconnect();
	unless ($dbh->{Active}) {
		$dbh = DBI->connect(...);
	}
	$dbh->do(something);
	sleep(1);
}

>
>> I understand that the above construct is dubious.
>
> It is not what I would have expected the users to do. :-)

:-)

> Question: What happens, if you set the RaiseError flag and trap
> the exception in the loop? (Using RaiseError is definitely
> recommended.) Does that help?

We run with RaiseError =>1 and PrintError => 0 exclusively. Changing 
those the other way doesn't make a difference either. It is silent. 
This was originally found on a redhat linux system, I just verified it 
happens on Mac OS X too (no errors reported, mem leaks). Both running 
Perl 5.8.0.

Thanks,

John

Thread
Mem leak upon recovering after a disconnectJohn Heitmann10 Jan
  • Re: Mem leak upon recovering after a disconnectJochen Wiedmann10 Jan
    • Re: Mem leak upon recovering after a disconnectJohn Heitmann10 Jan