laravel/framework · error · LostConnectionException
Lost connection and no reconnector available.
Error message
Lost connection and no reconnector available.
What it means
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.
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.
Example fix
// before
$conn = new MySqlConnection($pdo, $db, $prefix);
$conn->reconnect();
// after
$conn = new MySqlConnection($pdo, $db, $prefix);
$conn->setReconnector(function ($connection) use ($factory, $config) {
$connection->setPdo($factory->makePdo($config));
});
$conn->reconnect(); Defensive patterns
Strategy: validation
Validate before calling
if (! is_callable($connection->getReconnector())) {
$connection->setReconnector(function ($conn) use ($factory, $config) {
$conn->setPdo($factory->makePdo($config));
});
}
$connection->reconnect(); Type guard
function hasReconnector(\Illuminate\Database\Connection $c): bool {
return is_callable($c->getReconnector());
} Try / catch
try {
$connection->reconnect();
} catch (\Illuminate\Database\LostConnectionException $e) {
// fall back to rebuilding the PDO handle directly
$connection->setPdo($factory->makePdo($config));
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Database hosts array is empty.
- Unsupported driver [ ].
- A driver must be specified.
- Database connection [ ] not configured.
- Database file at path
AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11).
Data as JSON: /api/errors/e4d6fb91731c744a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Illuminate/Database/Connection.php:1056
}
throw $e;
}
/**
* Reconnect to the database.
*
* @return mixed|false
*
* @throws \Illuminate\Database\LostConnectionException
*/
public function reconnect()
{
if (is_callable($this->reconnector)) {
return call_user_func($this->reconnector, $this);
}
throw new LostConnectionException('Lost connection and no reconnector available.');
}
/**
* Reconnect to the database if a PDO connection is missing.
*
* @return void
*/
public function reconnectIfMissingConnection()
{
if (is_null($this->pdo)) {
$this->reconnect();
}
}
/**
* Disconnect from the underlying PDO connection.
*
* @return voidView on GitHub (pinned to e0f6eb3518)