From: Tim Starling Date: Sun, 14 Aug 2005 04:42:55 +0000 (+0000) Subject: fixed connection error handling X-Git-Tag: 1.6.0~1993 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=34331f8e2abc225dcbd1213a3e7944fc033d6c18;p=lhc%2Fweb%2Fwiklou.git fixed connection error handling --- diff --git a/includes/Database.php b/includes/Database.php index 2b986a668f..55932b5c18 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -260,7 +260,6 @@ class Database { if ( !$success ) { $this->reportConnectionError(); - $this->close(); } $this->mOpened = $success; return $success; @@ -289,16 +288,15 @@ class Database { /** * @access private * @param string $msg error message ? - * @todo parameter $msg is not used */ - function reportConnectionError( $msg = '') { + function reportConnectionError() { if ( $this->mFailFunction ) { if ( !is_int( $this->mFailFunction ) ) { $ff = $this->mFailFunction; $ff( $this, $this->lastError() ); } } else { - wfEmergencyAbort( $this, mysql_error() ); + wfEmergencyAbort( $this, $this->lastError() ); } } @@ -614,7 +612,13 @@ class Database { */ function lastError() { if ( $this->mConn ) { + # Even if it's non-zero, it can still be invalid + wfSuppressWarnings(); $error = mysql_error( $this->mConn ); + if ( !$error ) { + $error = mysql_error(); + } + wfRestoreWarnings(); } else { $error = mysql_error(); } @@ -1671,7 +1675,7 @@ class ResultWrapper { */ function wfEmergencyAbort( &$conn, $error ) { global $wgTitle, $wgUseFileCache, $title, $wgInputEncoding, $wgOutputEncoding; - global $wgSitename, $wgServer; + global $wgSitename, $wgServer, $wgMessageCache; # I give up, Brion is right. Getting the message cache to work when there is no DB is tricky. # Hard coding strings instead. @@ -1713,6 +1717,10 @@ border=\"0\" ALT=\"Google\"> header( 'Cache-control: none' ); header( 'Pragma: nocache' ); } + + # No database access + $wgMessageCache->disable(); + $msg = wfGetSiteNotice(); if($msg == '') { $msg = str_replace( '$1', $error, $noconnect ); diff --git a/includes/LoadBalancer.php b/includes/LoadBalancer.php index 54fc617d9b..c716d39553 100644 --- a/includes/LoadBalancer.php +++ b/includes/LoadBalancer.php @@ -27,7 +27,7 @@ define( 'DB_WRITE', -2 ); */ class LoadBalancer { /* private */ var $mServers, $mConnections, $mLoads, $mGroupLoads; - /* private */ var $mFailFunction; + /* private */ var $mFailFunction, $mErrorConnection; /* private */ var $mForce, $mReadIndex, $mLastIndex; /* private */ var $mWaitForFile, $mWaitForPos, $mWaitTimeout; /* private */ var $mLaggedSlaveMode; @@ -40,6 +40,7 @@ class LoadBalancer { $this->mReadIndex = -1; $this->mForce = -1; $this->mLastIndex = -1; + $this->mErrorConnection = false; } function newFromParams( $servers, $failFunction = false, $waitTimeout = 10 ) @@ -348,6 +349,10 @@ class LoadBalancer { $i = $this->getWriterIndex(); } } + # Couldn't find a working server in getReaderIndex()? + if ( $i === false ) { + $this->reportConnectionError( $this->mErrorConnection ); + } # Now we have an explicit index into the servers array $this->openConnection( $i, $fail ); @@ -375,6 +380,7 @@ class LoadBalancer { if ( $fail ) { $this->reportConnectionError( $this->mConnections[$i] ); } + $this->mErrorConnection = $this->mConnections[$i]; $this->mConnections[$i] = false; $success = false; } @@ -435,7 +441,7 @@ class LoadBalancer { if ( $this->mFailFunction ) { $conn->failFunction( $this->mFailFunction ); } else { - $conn->failFunction( 'wfEmergencyAbort' ); + $conn->failFunction( false ); } $conn->reportConnectionError(); $reporting = false;