cvsuser 05/11/21 12:24:58
Modified: App-Repository/lib/App/Repository DBI.pm MySQL.pm
Log:
retry when _connect() gets a Lost connection
Revision Changes Path
1.32 +22 -3 p5ee/App-Repository/lib/App/Repository/DBI.pm
Index: DBI.pm
===================================================================
RCS file: /cvs/public/p5ee/App-Repository/lib/App/Repository/DBI.pm,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- DBI.pm 15 Nov 2005 16:45:46 -0000 1.31
+++ DBI.pm 21 Nov 2005 20:24:57 -0000 1.32
@@ -177,7 +177,26 @@
if (!defined $self->{dbh}) {
my $dsn = $self->_dsn();
my $attr = $self->_attr();
- $self->{dbh} = DBI->connect($dsn, $self->{dbuser}, $self->{dbpass},
$attr);
+
+ while (1) {
+ eval {
+ $self->{dbh} = DBI->connect($dsn, $self->{dbuser},
$self->{dbpass}, $attr);
+ };
+ if ($@) {
+ delete $self->{dbh};
+ if ($@ =~ /Lost connection/ || $@ =~ /server has gone away/)
{
+ $self->{context}->log("DBI Exception (retrying) in
_connect(): $@");
+ sleep(1);
+ }
+ else {
+ $self->{context}->log("DBI Exception (fail) in
_connect(): $@");
+ die $@;
+ }
+ }
+ else {
+ last;
+ }
+ }
die "Can't connect to database" if (!$self->{dbh});
}
1.12 +24 -5 p5ee/App-Repository/lib/App/Repository/MySQL.pm
Index: MySQL.pm
===================================================================
RCS file: /cvs/public/p5ee/App-Repository/lib/App/Repository/MySQL.pm,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- MySQL.pm 9 Aug 2005 18:55:48 -0000 1.11
+++ MySQL.pm 21 Nov 2005 20:24:57 -0000 1.12
@@ -39,14 +39,33 @@
if (!defined $self->{dbh}) {
my $dsn = $self->_dsn();
my $attr = $self->_attr();
- $self->{dbh} = DBI->connect($dsn, $self->{dbuser}, $self->{dbpass},
$attr);
- $self->{dbh}{mysql_auto_reconnect} = 1;
+
+ while (1) {
+ eval {
+ $self->{dbh} = DBI->connect($dsn, $self->{dbuser},
$self->{dbpass}, $attr);
+ $self->{dbh}{mysql_auto_reconnect} = 1;
+ };
+ if ($@) {
+ delete $self->{dbh};
+ if ($@ =~ /Lost connection/ || $@ =~ /server has gone away/)
{
+ $self->{context}->log("DBI Exception (retrying) in
_connect(): $@");
+ sleep(1);
+ }
+ else {
+ $self->{context}->log("DBI Exception (fail) in
_connect(): $@");
+ die $@;
+ }
+ }
+ else {
+ last;
+ }
+ }
+ die "Can't connect to database" if (!$self->{dbh});
}
&App::sub_exit(defined $self->{dbh}) if ($App::trace);
return(defined $self->{dbh});
}
-
sub _dsn {
&App::sub_entry if ($App::trace);
my ($self) = @_;