mongodb/node-mongodb-native · error · MongoOperationTimeoutError

Server roundtrip time is greater than the time remaining

Error message

Server roundtrip time is greater than the time remaining

What it means

A MongoOperationTimeoutError thrown in Connection.sendWire when Client-Side Operation Timeout (CSOT) is enabled. After writing the command, the driver checks whether the remaining operation budget is at least minRoundTripTime; if not, there is no point waiting for the server reply. This is a pre-read guard that fails fast rather than starting a read that cannot complete in time.

Solutions

  1. Increase timeoutMS to accommodate network round-trip time and server processing.
  2. Investigate and reduce network latency or server-side query cost.
  3. Set minRoundTripTime appropriately via serverSelectionRTT or ensure local/low-latency connections.
  4. Profile with serverStatus / driver logging to confirm RTT vs. configured timeout budget.

Example fix

// before
const client = new MongoClient(uri, { timeoutMS: 1000 }); // too tight

// after
const client = new MongoClient(uri, { timeoutMS: 10000 });
Defensive patterns

Strategy: validation

Validate before calling

// Validate timeout budget against expected RTT before issuing the operation
const rttMs = 100; // observed/approximate round-trip
if (timeoutMS != null && timeoutMS <= rttMs) {
  throw new Error('timeoutMS must exceed network round-trip time');
}

Try / catch

try {
  await coll.findOne({}, { timeoutMS });
} catch (e) {
  if (e instanceof MongoOperationTimeoutError) { /* increase timeoutMS and retry */ }
  else throw e;
}

Prevention

When it happens

Trigger: Setting timeoutMS on the client or operation such that, after command serialization and socket write, remainingTimeMS < minRoundTripTime. Occurs under CSOT (timeoutMS-based) mode when the operation is already near its budget exhaustion at the point of reading the response.

Common situations: Tight timeoutMS values on slow/latent network links; operations where server-side processing plus network RTT exceeds the configured timeout; enabling CSOT globally with a small timeoutMS on a high-latency deployment.

Related errors


AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11). Data as JSON: /api/errors/cede5df0e7103a6e. Report an issue: GitHub.

Appendix: source

Thrown at src/cmap/connection.ts:487

        agreedCompressor: this.description.compressor ?? 'none',
        zlibCompressionLevel: this.description.zlibCompressionLevel,
        timeoutContext: options.timeoutContext,
        signal: options.signal
      });

      if (message.moreToCome) {
        yield MongoDBResponse.empty;
        return;
      }

      this.throwIfAborted();

      if (
        options.timeoutContext?.csotEnabled() &&
        options.timeoutContext.minRoundTripTime != null &&
        options.timeoutContext.remainingTimeMS < options.timeoutContext.minRoundTripTime
      ) {
        throw new MongoOperationTimeoutError(
          'Server roundtrip time is greater than the time remaining'
        );
      }

      for await (const response of this.readMany(options)) {
        this.socket.setTimeout(0);
        const bson = response.parse();

        const document = (responseType ?? MongoDBResponse).make(bson);

        yield document;
        this.throwIfAborted();

        this.socket.setTimeout(timeout);
      }
    } finally {
      this.socket.setTimeout(0);
    }

View on GitHub (pinned to dce7939f86)