From 6bfa593988276ccaafaf1b7828fcb573c87b4b85 Mon Sep 17 00:00:00 2001 From: Alexei Sorokin Date: Fri, 13 Sep 2019 22:08:42 +0300 Subject: [PATCH] [DAEMONS] Move resetDb to the Daemon class As it is used inside the Daemon class now, it should always be available. --- lib/util/daemon.php | 35 +++++++++++++++++++++++++++++++++++ lib/util/spawningdaemon.php | 35 ----------------------------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/lib/util/daemon.php b/lib/util/daemon.php index fa1e47cfcd..c7d8329412 100644 --- a/lib/util/daemon.php +++ b/lib/util/daemon.php @@ -41,6 +41,41 @@ class Daemon $this->_id = $id; } + /** + * Reconnect to the database for each child process, + * or they'll get very confused trying to use the + * same socket. + */ + protected function resetDb() + { + global $_DB_DATAOBJECT; + + // Can't be called statically + $user = new User(); + $conn = $user->getDatabaseConnection(); + $conn->disconnect(); + + // Remove the disconnected connection from the list + foreach ($_DB_DATAOBJECT['CONNECTIONS'] as $k => $v) { + if ($v === $conn) { + unset($_DB_DATAOBJECT['CONNECTIONS'][$k]); + } + } + + // Reconnect main memcached, or threads will stomp on + // each other and corrupt their requests. + $cache = Cache::instance(); + if ($cache) { + $cache->reconnect(); + } + + // Also reconnect memcached for status_network table. + if (!empty(Status_network::$cache)) { + Status_network::$cache->close(); + Status_network::$cache = null; + } + } + public function background() { // Database connection will likely get lost after forking diff --git a/lib/util/spawningdaemon.php b/lib/util/spawningdaemon.php index 3eb5e72e4b..a1a357b923 100644 --- a/lib/util/spawningdaemon.php +++ b/lib/util/spawningdaemon.php @@ -189,41 +189,6 @@ abstract class SpawningDaemon extends Daemon exit($exitCode); } - /** - * Reconnect to the database for each child process, - * or they'll get very confused trying to use the - * same socket. - */ - protected function resetDb() - { - global $_DB_DATAOBJECT; - - // Can't be called statically - $user = new User(); - $conn = $user->getDatabaseConnection(); - $conn->disconnect(); - - // Remove the disconnected connection from the list - foreach ($_DB_DATAOBJECT['CONNECTIONS'] as $k => $v) { - if ($v === $conn) { - unset($_DB_DATAOBJECT['CONNECTIONS'][$k]); - } - } - - // Reconnect main memcached, or threads will stomp on - // each other and corrupt their requests. - $cache = Cache::instance(); - if ($cache) { - $cache->reconnect(); - } - - // Also reconnect memcached for status_network table. - if (!empty(Status_network::$cache)) { - Status_network::$cache->close(); - Status_network::$cache = null; - } - } - public function log($level, $msg) { common_log($level, get_class($this) . ' ('. $this->get_id() .'): '.$msg);