{"record":{"id":"e4d6fb91731c744a","repo":"laravel/framework","slug":"lost-connection-and-no-reconnector-available","errorCode":null,"errorMessage":"Lost connection and no reconnector available.","messagePattern":"Lost connection and no reconnector available\\.","errorType":"exception","errorClass":"LostConnectionException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Connection.php","lineNumber":1056,"sourceCode":"        }\n\n        throw $e;\n    }\n\n    /**\n     * Reconnect to the database.\n     *\n     * @return mixed|false\n     *\n     * @throws \\Illuminate\\Database\\LostConnectionException\n     */\n    public function reconnect()\n    {\n        if (is_callable($this->reconnector)) {\n            return call_user_func($this->reconnector, $this);\n        }\n\n        throw new LostConnectionException('Lost connection and no reconnector available.');\n    }\n\n    /**\n     * Reconnect to the database if a PDO connection is missing.\n     *\n     * @return void\n     */\n    public function reconnectIfMissingConnection()\n    {\n        if (is_null($this->pdo)) {\n            $this->reconnect();\n        }\n    }\n\n    /**\n     * Disconnect from the underlying PDO connection.\n     *\n     * @return void","sourceCodeStart":1038,"sourceCodeEnd":1074,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Connection.php#L1038-L1074","documentation":"Thrown by Connection::reconnect() as a LostConnectionException when the connection's reconnector callable is missing. The reconnector is a Closure that knows how to rebuild the PDO handle (e.g. by asking the DatabaseManager to re-run the connector). Without it the framework cannot recover from a dropped socket, so it fails loudly instead of silently retrying with no way to reconnect.","triggerScenarios":"Calling $connection->reconnect() or $connection->reconnectIfMissingConnection() on a Connection whose setReconnector() was never invoked, or whose reconnector was set to a non-callable value. Happens with bare Connection instances, Capsule setups that skip reconnector wiring, or custom Connection subclasses.","commonSituations":"Long-running daemons/queue workers using a hand-built Connection; tests that construct a Connection directly and then trigger a query after closing the handle; misconfigured Capsule\\Manager that did not call setReconnector on the built connection.","solutions":["Obtain connections via the DatabaseManager (DB::connection(...)), which assigns the reconnector automatically.","If you hold a raw Connection, call $connection->setReconnector(fn ($connection) => $connection->setPdo($factory->makePdo($config))) before any query.","Ensure the reconnector is a Closure/callable and is never overwritten with null.","For daemons, prefer DB::reconnect($name) / DB::disconnect($name) over reconnect() on the Connection itself."],"exampleFix":"// before\n$conn = new MySqlConnection($pdo, $db, $prefix);\n$conn->reconnect();\n\n// after\n$conn = new MySqlConnection($pdo, $db, $prefix);\n$conn->setReconnector(function ($connection) use ($factory, $config) {\n    $connection->setPdo($factory->makePdo($config));\n});\n$conn->reconnect();","handlingStrategy":"validation","validationCode":"if (! is_callable($connection->getReconnector())) {\n    $connection->setReconnector(function ($conn) use ($factory, $config) {\n        $conn->setPdo($factory->makePdo($config));\n    });\n}\n$connection->reconnect();","typeGuard":"function hasReconnector(\\Illuminate\\Database\\Connection $c): bool {\n    return is_callable($c->getReconnector());\n}","tryCatchPattern":"try {\n    $connection->reconnect();\n} catch (\\Illuminate\\Database\\LostConnectionException $e) {\n    // fall back to rebuilding the PDO handle directly\n    $connection->setPdo($factory->makePdo($config));\n}","preventionTips":["Always obtain connections through the DatabaseManager, which sets the reconnector.","When building a Connection by hand, call setReconnector() with a Closure that can rebuild PDO.","In long-running workers, use DB::reconnect($name) rather than reconnect() on the bare Connection."],"tags":["database","connection","network","configuration","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}