{"record":{"id":"6ca0af7feb0cb9d3","repo":"nats-io/nats-server","slug":"timeout-after-v-request-type-q-on-q-reply-q","errorCode":null,"errorMessage":"timeout after %v: request type %q on %q (reply=%q)","messagePattern":"timeout after (.+?): request type %q on %q \\(reply=%q\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mqtt.go","lineNumber":1752,"sourceCode":"\t\t\ti := r2i[r.reply]\n\t\t\tresponses[i] = r\n\t\t\tc++\n\t\t\tif c == len(msgs) {\n\t\t\t\treturn responses, nil\n\t\t\t}\n\n\t\tcase <-jsa.quitCh:\n\t\t\treturn nil, ErrServerNotRunning\n\n\t\tcase <-t.C:\n\t\t\tvar reply string\n\t\t\tnow := time.Now()\n\t\t\tfor reply = range r2i { // preserve the last value for Errorf\n\t\t\t\tjsa.replies.Delete(reply)\n\t\t\t}\n\n\t\t\tif len(msgs) == 1 {\n\t\t\t\treturn responses, fmt.Errorf(\"timeout after %v: request type %q on %q (reply=%q)\", now.Sub(start), kind, subject, reply)\n\t\t\t} else {\n\t\t\t\treturn responses, fmt.Errorf(\"timeout after %v: request type %q on %q: got %d out of %d\", now.Sub(start), kind, subject, c, len(msgs))\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc (jsa *mqttJSA) sendAck(ackSubject string) {\n\t// Send to the ack subject with no payload.\n\tjsa.sendMsg(ackSubject, nil)\n}\n\nfunc (jsa *mqttJSA) sendMsg(subj string, msg []byte) {\n\tif subj == _EMPTY_ {\n\t\treturn\n\t}\n\t// We pass -1 for the hdr so that the send loop does not need to\n\t// add the \"client info\" header. This is not a JS API request per se.","sourceCodeStart":1734,"sourceCodeEnd":1770,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/mqtt.go#L1734-L1770","documentation":"This is the single-response variant of the internal JSAPI request timeout in the MQTT JetStream adapter. A request (stream lookup, create, update, consumer create, etc.) was sent on an internal reply subject and no response arrived within the timeout; when exactly one reply inbox was registered the error reports the reply subject for debugging.","triggerScenarios":"JetStream API slow or unresponsive (leader election, overloaded server, no responders); request timeout exceeded while waiting for a single JS API response during MQTT setup operations (lookupStream, createStream, updateStream, createEphemeralConsumer).","commonSituations":"Under-provisioned servers under load; JetStream raft elections in progress; network partition in a cluster; very large meta state slowing JS API responses.","solutions":["Check JetStream cluster health and wait for leader elections to settle, then retry","Increase server capacity or reduce load; timeouts under heavy load are the usual cause","Investigate network partition/latency between clustered servers","If timeouts are systemic, review jetstream configuration and client reconnect/backoff behavior"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-check JS API responsiveness:\nctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\ndefer cancel()\n_, err := js.AccountInfo(nats.Context(ctx))\n// err on timeout means JS API is slow — do not start MQTT workload yet","typeGuard":null,"tryCatchPattern":"if strings.Contains(err.Error(), \"timeout after\") && strings.Contains(err.Error(), \"request type\") {\n    // exponential backoff retry; check cluster health before next attempt\n    return retryWithBackoff(op)\n}","preventionTips":["Monitor JS API latency and leader elections","Size servers so JS API responds well under expected load","Fix network partitions promptly; they surface as these timeouts"],"tags":["jetstream","mqtt","timeout","api-request"],"backgroundTag":"request-timeout","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}