From ce57a03aec280b7187ad5e15c0158151638575d6 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 25 Aug 2016 22:20:23 -0700 Subject: [PATCH] Make database ping() method avoid starting transactions Also use the $ignoreErrors flag to simplify the code. Change-Id: Ieb685366b35487abcd618eb73cf67f4c266a70c7 --- includes/db/Database.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 59c1207e49..e07836b225 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -2972,13 +2972,14 @@ abstract class DatabaseBase implements IDatabase { if ( $this->isOpen() && ( microtime( true ) - $this->lastPing ) < self::PING_TTL ) { return true; } - try { - // This will reconnect if possible, or error out if not - $this->query( "SELECT 1 AS ping", __METHOD__ ); - return true; - } catch ( DBError $e ) { - return false; - } + + $ignoreErrors = true; + $this->clearFlag( DBO_TRX, self::REMEMBER_PRIOR ); + // This will reconnect if possible or return false if not + $ok = (bool)$this->query( "SELECT 1 AS ping", __METHOD__, $ignoreErrors ); + $this->restoreFlags( self::RESTORE_PRIOR ); + + return $ok; } /** -- 2.20.1