Skip to content
TheChatArchiveThe Chat Archive
xiaomi/mimo-v2.5-pro· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION [Bug] Broker may accept duplicate messages after dedup recovery race…

  1. User

    ISSUE DESCRIPTION

    [Bug] Broker may accept duplicate messages after dedup recovery race

    Issue Description

    Message deduplication recovery can be started more than once for the same topic before the first recovery replay completes.

    MessageDeduplication defines a Recovering status to prevent overlapping transitions, but the enable path starts dedup cursor replay without first changing the status to Recovering.

    Because of that, another checkStatus() call can still observe Initialized or Disabled and start a second replay for the same dedup cursor.

    One practical trigger path is topic load with existing topic-level policies:

    TimeFlow A: existing topic-level policy during loadFlow B: normal topic load chainDedup status / effect
    T1initTopicPolicy() loads existing topic policiesdedup status is Initialized or Disabled
    T2onUpdate() applies topic policies and calls checkDeduplicationStatus()first dedup recovery replay starts
    T3first replay is still running asynchronouslystatus is still Initialized or Disabled
    T4topic load continues and BrokerService explicitly calls checkDeduplicationStatus()
    T5second check also enters the enable pathsecond replay starts for the same dedup cursor
    T6first replay rebuilds producer sequence statesecond replay also rebuilds producer sequence stateoverlapping replay can advance shared replay/cursor state

    Dedup recovery rebuilds producer sequence information from the dedup cursor. If overlapping replay leaves the recovered sequence state incomplete or inconsistent, the broker may fail to identify already-published messages as duplicates.

    The impact is that duplicate messages can be accepted after topic load or policy refresh even though message deduplication is enabled.

    There is also a retry gap after recovery failure. If enabling deduplication fails transiently, the status moves to Failed, but later checks do not retry enabling even when the topic policy still requires deduplication.

    Error messages

    There may be no error message. This is a race in the dedup recovery state machine.

    Reproducing the issue

    A deterministic unit-level reproduction can be built by delaying the first dedup recovery replay and invoking checkStatus() again before the first replay completes:

    1. Keep MessageDeduplication in Initialized or Disabled.
    2. Call checkStatus() once and delay async cursor open or replay completion.
    3. Call checkStatus() again before the first recovery finishes.
    4. Observe that the second call enters the enable path again and starts another replay.

    A production-like trigger path is:

    1. Enable message deduplication.
    2. Use a topic with existing topic-level policies.
    3. Load or reload the topic.
    4. During topic load, initTopicPolicy() can invoke onUpdate(), which applies topic policies and calls checkDeduplicationStatus().
    5. The normal topic load chain later calls checkDeduplicationStatus() again.
    6. If the first recovery replay is still in progress, both checks can start overlapping dedup replay.

    Expected behavior

    • Deduplication should enter Recovering before starting recovery replay.
    • Concurrent status checks should not start another recovery while replay is in progress.
    • If enable fails transiently, a later check should retry enabling when deduplication is still required by policy.

    Actual behavior

    • Enable starts replay while status remains Initialized or Disabled.
    • Another checkStatus() can start a second replay before the first completes.
    • Failed status does not retry enable even when deduplication should still be enabled.

    Additional information

    A fix has been proposed in #25953.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /pulsar, current file: none) bash-$

  2. Assistant

    I'll start by exploring the repository to understand the codebase structure and locate the relevant files. Let's first get a high-level view.

  3. Assistant

    Let me examine the main MessageDeduplication.java file to understand the current implementation and the issue.

  4. Assistant

    The file is truncated. Let me read the full file to understand the complete checkStatus() and replayCursor() methods:

  5. Assistant

    Let me look at the complete file to understand the full checkStatus method and related code.

  6. Assistant

    Let me scroll through the file to see the full checkStatus method and the rest of the code.

  7. Assistant

    Let me see more of the file, especially the checkStatus() and replayCursor() methods:

  8. Assistant

    Let me look at the checkStatus and replayCursor methods more carefully.

  9. Assistant

    Now I can see the issue clearly. Let me also look at the referenced PR #25953 to understand what fix was proposed:

  10. Assistant

    Let me check if there's a reference to PR #25953 in the repository:

  11. Assistant

    Now let me look at the existing tests for MessageDeduplication to understand the testing patterns:

  12. Assistant

    Now I understand the issue clearly. Let me analyze the checkStatus() method in detail:

    1. When status == Status.Disabled || status == Status.Initialized and shouldBeEnabled is true, the method starts the cursor replay but doesn't set status to Recovering before starting the async operation.
    2. If checkStatus() is called again while the first replay is still running, the status is still Initialized or Disabled, so it enters the enable path again and starts another replay.
    3. If enabling fails, status becomes Failed, but there's no retry logic for Failed status.

    Let me fix the MessageDeduplication.java file:

  13. Assistant

    Now I understand the issue clearly. Let me analyze the checkStatus() method:

    1. Race condition: When status == Status.Disabled || status == Status.Initialized and shouldBeEnabled is true, the method starts the cursor replay but doesn't set status to Recovering before starting the async operation.
    2. No retry for Failed status: If enabling fails, status becomes Failed, but there's no retry logic for Failed status.

    Let me now implement the fix. I need to:

    1. Set status = Status.Recovering before starting the cursor open/replay
    2. Add retry logic for Failed status when deduplication should still be enabled
  14. Assistant

    Now let me verify the full checkStatus method to make sure everything looks correct:

  15. Assistant

    The fix looks correct. Let me verify the changes are complete by looking at the git diff:

  16. Assistant

    Now let me run the existing tests related to deduplication to make sure the fix doesn't break anything. First, let me check which test files exist:

  17. Assistant

    Let me look at the existing tests to understand what they're testing and if my changes might break them.

  18. Assistant

    Let me look at the BrokerMessageDeduplicationTest to see if it tests the checkStatus() method:

  19. Assistant

    Let me look at the checkStatusFail test to understand what it's testing and if our changes affect it:

  20. Assistant

    Let me also look at TopicDuplicationTest which might be more relevant:

  21. Assistant

    Let me look at the entire BrokerMessageDeduplicationTest class to see if there are tests that check status transitions:

  22. Assistant

    Let me check if there are any references to checkDeduplicationStatus in the persistent topic class:

  23. Assistant

    Now let me verify the fix is correct by running the existing tests. First, let me check if there are any build tools available:

  24. Assistant

    Let me check the build system.

  25. Assistant

    Let me look at the build system for this project.

  26. Assistant

    Let me find the build files.

  27. Assistant

    It seems like the project uses Gradle. Let me check for the main build file:

  28. Assistant

    Let me check if there's a way to compile just the relevant file:

  29. Assistant

    Let me run the existing unit test for the BrokerMessageDeduplicationTest to see if the checkStatusFail test passes with our changes:

  30. Assistant

    The tests pass. Let me also run the MessageDuplicationTest to make sure nothing is broken:

  31. Assistant

    Let me also run the TopicDuplicationTest to make sure it passes:

  32. Assistant

    All existing tests pass. Let me review the final state of the fix one more time:

  33. Assistant

    Let me verify the full logic of the fixed checkStatus() method to make sure it handles all the cases correctly:

  34. Assistant

    The fix looks correct. Let me run all deduplication-related tests to make sure everything works:

  35. Assistant

    All deduplication-related tests pass. Let me verify the fix one final time by looking at the complete change:

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.