{"record":{"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/dce7939f86fb283e167ad709955abedb7bf23124/src/cmap/connection.ts#L469-L505","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Increase timeoutMS to accommodate network round-trip time and server processing.","Investigate and reduce network latency or server-side query cost.","Set minRoundTripTime appropriately via serverSelectionRTT or ensure local/low-latency connections.","Profile with serverStatus / driver logging to confirm RTT vs. configured timeout budget."],"exampleFix":"// before\nconst client = new MongoClient(uri, { timeoutMS: 1000 }); // too tight\n\n// after\nconst client = new MongoClient(uri, { timeoutMS: 10000 });","handlingStrategy":"validation","validationCode":"// Validate timeout budget against expected RTT before issuing the operation\nconst rttMs = 100; // observed/approximate round-trip\nif (timeoutMS != null && timeoutMS <= rttMs) {\n  throw new Error('timeoutMS must exceed network round-trip time');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await coll.findOne({}, { timeoutMS });\n} catch (e) {\n  if (e instanceof MongoOperationTimeoutError) { /* increase timeoutMS and retry */ }\n  else throw e;\n}","preventionTips":["Size timeoutMS to RTT + expected server processing time.","Monitor observed RTT via SDAM and adjust.","Avoid globally-tight timeoutMS; use per-operation budgets."],"tags":["timeout","csot","network","rtt"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}