mongodb/node-mongodb-native · critical · MongoRuntimeError

client.connect did not create a topology but also did not th

Error message

client.connect did not create a topology but also did not throw

What it means

autoConnect (src/operations/execute_operation.ts:153) throws a MongoRuntimeError when client.connect() resolved without error but client.topology is still null. This is an internal invariant violation indicating a driver bug or an extremely abnormal connect path — connect() should either establish a topology or throw.

Source

Thrown at src/operations/execute_operation.ts:153

      await session.endSession();
    }
  }
}

/**
 * Connects a client if it has not yet been connected
 * @internal
 */
export async function autoConnect(client: MongoClient): Promise<Topology> {
  if (client.topology == null) {
    if (client.s.hasBeenClosed) {
      throw new MongoNotConnectedError('Client must be connected before running operations');
    }
    client.s.options.__skipPingOnConnect = true;
    try {
      await client.connect();
      if (client.topology == null) {
        throw new MongoRuntimeError(
          'client.connect did not create a topology but also did not throw'
        );
      }
      return client.topology;
    } finally {
      delete client.s.options.__skipPingOnConnect;
    }
  }
  return client.topology;
}

/** @internal */
type RetryOptions = {
  session: ClientSession | undefined;
  readPreference: ReadPreference;
  topology: Topology;
  timeoutContext: TimeoutContext;
};

View on GitHub (pinned to 3366c21a63)

Solutions

  1. If you encounter this, report it as a driver bug with reproduction steps and driver/server versions.
  2. Verify you are not monkey-patching MongoClient or its connect method.
  3. Upgrade to the latest driver patch release in case the issue was already fixed.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await collection.find({}).toArray();
} catch (err) {
  if (err instanceof MongoRuntimeError && /did not create a topology/.test(err.message)) {
    // report driver bug; create a fresh client
  } else throw err;
}

Prevention

When it happens

Trigger: This should not occur under normal conditions. It would only surface if a custom topology plugin, a monkey-patch, or a driver bug causes connect() to succeed without populating the topology.

Common situations: Driver regression after an internal refactor, a third-party module patching MongoClient.connect, or a very exotic runtime environment. Practically unseen in production.

Related errors


AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04). Data as JSON: /data/errors/333c1ca9548f8997.json. Report an issue: GitHub.