Description
db_check_reconnect() at lib/database.php:247 takes $db_conn by value,
not by reference. When a MySQL connection drops (error 2002/2006), the
function creates a new PDO object in the global $database_sessions array,
but the caller's local $db_conn still points to the dead instance. The
retry loop executes $db_conn->prepare() on the dead object, fails 5
times, and fatally aborts.
Long-running daemons (script_server.php, poller.php) permanently crash
instead of recovering after a brief MySQL restart.
Remediation
Change the function signature to pass by reference:
function db_check_reconnect(&$db_conn = false, $log = true)
And assign the new PDO object back to $db_conn inside the function.
Description
db_check_reconnect() at lib/database.php:247 takes $db_conn by value,
not by reference. When a MySQL connection drops (error 2002/2006), the
function creates a new PDO object in the global $database_sessions array,
but the caller's local $db_conn still points to the dead instance. The
retry loop executes $db_conn->prepare() on the dead object, fails 5
times, and fatally aborts.
Long-running daemons (script_server.php, poller.php) permanently crash
instead of recovering after a brief MySQL restart.
Remediation
Change the function signature to pass by reference:
function db_check_reconnect(&$db_conn = false, $log = true)
And assign the new PDO object back to $db_conn inside the function.