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

  1. Obtain connections via the DatabaseManager (DB::connection(...)), which assigns the reconnector automatically.
  2. If you hold a raw Connection, call $connection->setReconnector(fn ($connection) => $connection->setPdo($factory->makePdo($config))) before any query.
  3. Ensure the reconnector is a Closure/callable and is never overwritten with null.
  4. 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

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


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 void

View on GitHub (pinned to e0f6eb3518)