{"record":{"id":"90d58a83dacef03e","repo":"mongodb/node-mongodb-native","slug":"unable-to-get-response-from-server","errorCode":null,"errorMessage":"Unable to get response from server","messagePattern":"Unable to get response from server","errorType":"exception","errorClass":"MongoUnexpectedServerResponseError","httpStatus":null,"severity":"error","filePath":"src/cmap/connection.ts","lineNumber":661,"sourceCode":"          }\n        } else {\n          if (\n            (Array.isArray(document?.writeErrors) &&\n              document.writeErrors.some(\n                error => error?.code === MONGODB_ERROR_CODES.MaxTimeMSExpired\n              )) ||\n            document?.writeConcernError?.code === MONGODB_ERROR_CODES.MaxTimeMSExpired\n          ) {\n            throw new MongoOperationTimeoutError('Server reported a timeout error', {\n              cause: new MongoServerError(document)\n            });\n          }\n        }\n      }\n\n      return document;\n    }\n    throw new MongoUnexpectedServerResponseError('Unable to get response from server');\n  }\n\n  public exhaustCommand(\n    ns: MongoDBNamespace,\n    command: Document,\n    options: CommandOptions,\n    replyListener: Callback\n  ) {\n    const exhaustLoop = async () => {\n      this.throwIfAborted();\n      for await (const reply of this.sendCommand(ns, command, options)) {\n        replyListener(undefined, reply);\n        this.throwIfAborted();\n      }\n      throw new MongoUnexpectedServerResponseError('Server ended moreToCome unexpectedly');\n    };\n\n    exhaustLoop().then(undefined, replyListener);","sourceCodeStart":643,"sourceCodeEnd":679,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/cmap/connection.ts#L643-L679","documentation":"A MongoUnexpectedServerResponseError thrown at the end of Connection.command when the sendCommand async generator completes without yielding a single document. Normally the server always replies with at least one document; reaching the 'no response' throw means the protocol exchange ended empty, which should never happen on a healthy connection.","triggerScenarios":"The sendCommand generator returns before yielding — e.g., the socket closed cleanly between write and read, or an internal generator control-flow path exited early. Typically a symptom of a dropped/reset connection or a proxy that half-closes the stream.","commonSituations":"Network middleboxes or load balancers that close idle connections without RST; TLS termination proxies with aggressive timeouts; driver bugs in older versions; connections reaped by the pool between write and read.","solutions":["Retry the operation with retryable reads/writes enabled (the default).","Investigate intermediate proxies/load balancers for premature connection closes.","Upgrade the driver — older versions had generator-control paths that could surface this spuriously.","Enable driver SDAM/command logging to correlate with connection close events."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"function isUnexpectedServerResponse(e: unknown): boolean {\n  return e?.constructor?.name === 'MongoUnexpectedServerResponseError';\n}","tryCatchPattern":"for (let attempt = 0; attempt < 3; attempt++) {\n  try {\n    return await operation();\n  } catch (e) {\n    if (e?.constructor?.name === 'MongoUnexpectedServerResponseError' && attempt < 2) continue;\n    throw e;\n  }\n}","preventionTips":["Enable retryable reads/writes (default) so transient drops are retried.","Investigate proxies/load balancers for premature connection closes.","Keep the driver up to date."],"tags":["protocol","unexpected-response","network","connection-drop"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}