{"id":"cede5df0e7103a6e","repo":"mongodb/node-mongodb-native","slug":"server-roundtrip-time-is-greater-than-the-time-rem","errorCode":null,"errorMessage":"Server roundtrip time is greater than the time remaining","messagePattern":"Server roundtrip time is greater than the time remaining","errorType":"exception","errorClass":"MongoOperationTimeoutError","httpStatus":null,"severity":"error","filePath":"src/cmap/connection.ts","lineNumber":487,"sourceCode":"        agreedCompressor: this.description.compressor ?? 'none',\n        zlibCompressionLevel: this.description.zlibCompressionLevel,\n        timeoutContext: options.timeoutContext,\n        signal: options.signal\n      });\n\n      if (message.moreToCome) {\n        yield MongoDBResponse.empty;\n        return;\n      }\n\n      this.throwIfAborted();\n\n      if (\n        options.timeoutContext?.csotEnabled() &&\n        options.timeoutContext.minRoundTripTime != null &&\n        options.timeoutContext.remainingTimeMS < options.timeoutContext.minRoundTripTime\n      ) {\n        throw new MongoOperationTimeoutError(\n          'Server roundtrip time is greater than the time remaining'\n        );\n      }\n\n      for await (const response of this.readMany(options)) {\n        this.socket.setTimeout(0);\n        const bson = response.parse();\n\n        const document = (responseType ?? MongoDBResponse).make(bson);\n\n        yield document;\n        this.throwIfAborted();\n\n        this.socket.setTimeout(timeout);\n      }\n    } finally {\n      this.socket.setTimeout(0);\n    }","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cmap/connection.ts#L469-L505","documentation":"Thrown in sendWire (src/cmap/connection.ts:482-490) when Client-Side Operation Timeouts (CSOT) are enabled, a minRoundTripTime was configured, and the remaining time budget is smaller than that minimum round-trip estimate. The driver reasons that the request cannot possibly complete in time, so it fails fast with a MongoOperationTimeoutError before reading any response frames.","triggerScenarios":"Setting timeoutMS on an operation (or globally) plus a minRoundTripTimeMS such that remaining time < min round trip. Triggered by any operation whose per-op timeout budget has nearly expired when the read phase begins - common with very small timeoutMS values or cascaded operations sharing one timeout context.","commonSituations":"Setting timeoutMS to a value barely above network latency (e.g. 5ms over a WAN); nested operations under one timeout context where earlier stages consumed most of the budget; misconfigured minRoundTripTimeMS; slow network with aggressive timeouts.","solutions":["Increase timeoutMS to comfortably exceed network round-trip time plus expected server work.","Remove or lower minRoundTripTimeMS if you set it manually.","Avoid sharing a single timeout context across many sequential operations; give each its own timeout.","Profile actual RTT with a ping and set timeoutMS >= 2-4x RTT + query cost."],"exampleFix":"// before\nawait coll.find({}, { timeoutMS: 5 }).toArray(); // too low for WAN\n\n// after\nawait coll.find({}, { timeoutMS: 1000 }).toArray();","handlingStrategy":"validation","validationCode":"function validateTimeoutVsRtt(timeoutMS: number, rttMS: number, minRtt?: number) {\n  const floor = minRtt ?? rttMS;\n  if (timeoutMS < floor * 2) {\n    throw new Error(`timeoutMS (${timeoutMS}) must exceed ~2x RTT (${rttMS})`);\n  }\n}","typeGuard":"function timeoutExceedsRtt(timeoutMS: number | undefined, rttMS: number): boolean {\n  return timeoutMS === undefined || timeoutMS > rttMS;\n}","tryCatchPattern":"import { MongoOperationTimeoutError } from 'mongodb';\ntry {\n  await collection.find({}, { timeoutMS: 10 }).toArray();\n} catch (e) {\n  if (e instanceof MongoOperationTimeoutError && /roundtrip/i.test(e.message)) {\n    // raise timeoutMS and retry with backoff\n  }\n  throw e;\n}","preventionTips":["Measure RTT to the server before choosing timeoutMS.","Set timeoutMS to at least 2-4x expected RTT plus query cost.","Do not set minRoundTripTimeMS larger than typical RTT."],"tags":["timeout","csot","network","configuration"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}