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

   ## Motivation
   
   `ScheduleMessageService.messageTimeUp` rewrites a delayed message back to 
its destination with
   
   ```java
   msgInner.setTopic(msgInner.getProperty(MessageConst.PROPERTY_REAL_TOPIC));
   String queueIdStr = 
msgInner.getProperty(MessageConst.PROPERTY_REAL_QUEUE_ID);
   int queueId = Integer.parseInt(queueIdStr);
   ```
   
   A delayed message in `SCHEDULE_TOPIC` whose destination properties are 
missing or malformed (corrupted properties string, or a hand-crafted message 
written straight into the system topic) makes this throw:
   
   - `Integer.parseInt(null)` / `NumberFormatException` propagates to 
`DeliverDelayedMessageTimerTask.executeOnTimeUp`, whose catch aborts the scan 
of the current consume-queue batch — the remaining messages of that batch each 
lose one delivery cycle and every occurrence logs a full stack trace.
   - a missing `PROPERTY_REAL_TOPIC` is worse: the topic becomes `null`, 
`putMessage` rejects it, `syncDeliver` returns false and the task reschedules 
the same offset forever, wedging that delay level.
   
   The adjacent real-topic guard (`[BUG] the real topic of schedule msg is ..., 
discard the msg`) already established that such messages must be discarded, but 
only for one specific wrong value, not for the missing/malformed cases.
   
   ## Modification
   
   - `messageTimeUp` validates `PROPERTY_REAL_TOPIC` and 
`PROPERTY_REAL_QUEUE_ID` before using them and returns `null` when the 
destination is unusable, logging a `[BUG] ... discard` line like the existing 
guard.
   - Both call sites (`executeOnTimeUp` and `PutResultProcess.doResend`) skip a 
null conversion result, so the rest of the batch is still processed in-cycle 
and a resend of a permanently malformed message is marked skip/exception 
instead of retrying.
   
   ## Test Evidence
   
   New test `testMessageTimeUpWithMalformedRealQueueId` covers: non-numeric 
queue id, missing queue id, missing real topic, and the well-formed case.
   
   ```
   docker exec rmq-build mvn -q -pl broker test 
-Dtest='ScheduleMessageServiceTest#testMessageTimeUpWithMalformedRealQueueId' 
-Dsurefire.failIfNoSpecifiedTests=true
   ```
   
   Before the fix:
   
   ```
   java.lang.reflect.InvocationTargetException
   Caused by: java.lang.NumberFormatException: For input string: "notANumber"
   Tests run: 1, Failures: 0, Errors: 1
   ```
   
   After the fix:
   
   ```
   docker exec rmq-build mvn -q -pl broker test 
-Dtest='ScheduleMessageServiceTest' -Dsurefire.failIfNoSpecifiedTests=true
   Tests run: 5, Failures: 0, Errors: 0, Skipped: 0   (includes the end-to-end 
testDeliverDelayedMessageTimerTask)
   ```
   
   No associated issue (self-discovered during a broker 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to