You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "zjncs (via GitHub)" <gi...@apache.org> on 2026/09/10 10:27:03 UTC

[PR] [ISSUE #D9] Guard consumeMessageDirectly against unresolvable msgId [rocketmq]

zjncs opened a new pull request, #11116:
URL: https://github.com/apache/rocketmq/pull/11116

   ## Motivation
   
   `AdminBrokerProcessor.consumeMessageDirectly` (backing `mqadmin consumeMessageDirectly` / console "trace/diagnose message") fetches the message by offset with no null check:
   
   ```java
   selectMappedBufferResult = this.brokerController.getMessageStore().selectOneMessageByOffset(messageId.getOffset());
   byte[] body = new byte[selectMappedBufferResult.getSize()];   // NPE when null
   ```
   
   `selectOneMessageByOffset` returns null when the offset no longer maps to a stored message — the commitlog segment was expired/deleted, or the msgId was never on this broker. The broker then throws a raw `NullPointerException` into the remoting layer instead of answering the admin request.
   
   Additionally, the `catch (UnknownHostException e) {}` block silently swallows msgId decode failures and falls through to `callConsumer` with a **null body**, so the consumer is invoked with an empty request and fails with an unrelated decode error far from the cause.
   
   ## Modification
   
   - If `selectOneMessageByOffset` returns null, respond `SYSTEM_ERROR` with remark `can not find message by id: <msgId>` and do not invoke the consumer.
   - On `UnknownHostException` (undecodable msgId), respond `SYSTEM_ERROR` with remark `can not decode message id: <msgId>` instead of forwarding a bodiless request.
   
   ## Test Evidence
   
   **Fail-before** (unpatched code, new test `AdminBrokerProcessorTest#testConsumeMessageDirectlyMessageNotFound` with a well-formed msgId whose offset is not stored):
   
   ```
   docker exec rmq-build mvn -q -pl broker test -Dtest='AdminBrokerProcessorTest#testConsumeMessageDirectlyMessageNotFound' -Dsurefire.failIfNoSpecifiedTests=true
   Tests run: 1, Errors: 1 ... java.lang.NullPointerException: Cannot invoke "...SelectMappedBufferResult.getSize()" because "selectMappedBufferResult" is null
   ```
   
   **Pass-after** (full class with the fix):
   
   ```
   docker exec rmq-build mvn -q -pl broker test -Dtest='AdminBrokerProcessorTest' -Dsurefire.failIfNoSpecifiedTests=true
   Tests run: 94, Failures: 0, Errors: 0, Skipped: 0
   ```
   
   No associated issue (self-discovered during a broker-module self-audit).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [ISSUE #D9] Guard consumeMessageDirectly against unresolvable msgId [rocketmq]

Posted by "zjncs (via GitHub) via commits" <co...@rocketmq.apache.org>.
zjncs closed pull request #11116: [ISSUE #D9] Guard consumeMessageDirectly against unresolvable msgId
URL: https://github.com/apache/rocketmq/pull/11116


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org