{"record":{"id":"157e59486a750b10","repo":"apache/rocketmq","slug":"sendmessage-call-timeout","errorCode":null,"errorMessage":"sendMessage call timeout","messagePattern":"sendMessage call timeout","errorType":"exception","errorClass":"RemotingTooMuchRequestException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java","lineNumber":577,"sourceCode":"        } else {\n            if (sendSmartMsg || msg instanceof MessageBatch) {\n                SendMessageRequestHeaderV2 requestHeaderV2 = SendMessageRequestHeaderV2.createSendMessageRequestHeaderV2(requestHeader);\n                request = RemotingCommand.createRequestCommand(msg instanceof MessageBatch ? RequestCode.SEND_BATCH_MESSAGE : RequestCode.SEND_MESSAGE_V2, requestHeaderV2);\n            } else {\n                request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE, requestHeader);\n            }\n        }\n        request.setBody(msg.getBody());\n\n        switch (communicationMode) {\n            case ONEWAY:\n                this.remotingClient.invokeOneway(addr, request, timeoutMillis);\n                return null;\n            case ASYNC:\n                final AtomicInteger times = new AtomicInteger();\n                long costTimeAsync = System.currentTimeMillis() - beginStartTime;\n                if (timeoutMillis < costTimeAsync) {\n                    throw new RemotingTooMuchRequestException(\"sendMessage call timeout\");\n                }\n                this.sendMessageAsync(addr, brokerName, msg, timeoutMillis - costTimeAsync, request, sendCallback, topicPublishInfo, instance,\n                    retryTimesWhenSendFailed, times, context, producer);\n                return null;\n            case SYNC:\n                long costTimeSync = System.currentTimeMillis() - beginStartTime;\n                if (timeoutMillis < costTimeSync) {\n                    throw new RemotingTooMuchRequestException(\"sendMessage call timeout\");\n                }\n                return this.sendMessageSync(addr, brokerName, msg, timeoutMillis - costTimeSync, request);\n            default:\n                assert false;\n                break;\n        }\n\n        return null;\n    }\n","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java#L559-L595","documentation":"Thrown by MQClientAPIImpl.sendMessage in ASYNC mode as RemotingTooMuchRequestException: the elapsed time since the request began (beginStartTime, set when the whole send workflow started, including message encoding and any earlier attempts) already exceeds the full timeout budget, so the remaining budget for the actual network call is negative and the send is rejected before invoking.","triggerScenarios":"Async send where timeoutMillis is smaller than time already spent building/encoding the request — e.g. very small sendMsgTimeout, large message body serialization, or retry attempts (retry 2+) reusing beginStartTime so prior failures consumed the entire budget.","commonSituations":"Producer sendMsgTimeout lowered from the 3000ms default; large batched messages; async retry after a slow first attempt; overloaded client thread pool delaying execution until after the deadline; clock-sensitive latency budgets in canary/latency-testing tools.","solutions":["Increase producer.setSendMsgTimeout(timeoutMillis)","Check the cause chain of earlier async failures — retries inherit the original deadline, so fix the root slowness (broker/network)","Reduce message body size or move serialization off the send path","Monitor client CPU: encoding and callback contention inflate costTime","If it only appears on retries, cap retryTimesWhenSendFailed or accept the exception as budget exhaustion"],"exampleFix":"// before\nproducer.setSendMsgTimeout(500); // too small for large payloads\nproducer.send(msg, new SendCallback() {...});\n\n// after\nproducer.setSendMsgTimeout(3000); // default, or higher for big messages\nproducer.send(msg, new SendCallback() {...});","handlingStrategy":"validation","validationCode":"// ensure timeout budget exceeds known encode time before async send\nlong encodeBudgetMs = 500; // measured for your payload shape\nif (producer.getSendMsgTimeout() <= encodeBudgetMs) {\n    producer.setSendMsgTimeout(encodeBudgetMs + 2500);\n}","typeGuard":null,"tryCatchPattern":"producer.send(msg, new SendCallback() {\n    public void onException(Throwable e) {\n        if (e instanceof RemotingTooMuchRequestException) {\n            // budget exhausted before invoke: raise sendMsgTimeout, do not blind-retry\n        }\n    }\n    public void onSuccess(SendResult r) {}\n});","preventionTips":["Do not shrink sendMsgTimeout below encode+network cost","Remember async retries share the original deadline — fix first-attempt slowness instead of re-sending","Benchmark message encoding cost for your payload size"],"tags":["rocketmq","timeout","producer","send","async"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}