Skip to content

fix: db_check_reconnect passes connection by value, breaking daemon reconnect #7029

@somethingwithproof

Description

@somethingwithproof

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions