ISSUE DESCRIPTION [Bug] Broker may accept duplicate messages after dedup recovery race…
- 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.
MessageDeduplicationdefines aRecoveringstatus to prevent overlapping transitions, but the enable path starts dedup cursor replay without first changing the status toRecovering.Because of that, another
checkStatus()call can still observeInitializedorDisabledand start a second replay for the same dedup cursor.One practical trigger path is topic load with existing topic-level policies:
Time Flow A: existing topic-level policy during load Flow B: normal topic load chain Dedup status / effect T1 initTopicPolicy()loads existing topic policiesdedup status is InitializedorDisabledT2 onUpdate()applies topic policies and callscheckDeduplicationStatus()first dedup recovery replay starts T3 first replay is still running asynchronously status is still InitializedorDisabledT4 topic load continues and BrokerServiceexplicitly callscheckDeduplicationStatus()T5 second check also enters the enable path second replay starts for the same dedup cursor T6 first replay rebuilds producer sequence state second replay also rebuilds producer sequence state overlapping 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. Assistant
Let me start by understanding the repository structure and the issue. The issue is about
MessageDeduplicationin Apache Pulsar. Let me explore the codebase to find the relevant files.The issue describes:
MessageDeduplicationdefines aRecoveringstatus to prevent overlapping transitions, but the enable path starts dedup cursor replay without first changing the status toRecovering.- Because of that, another
checkStatus()call can still observeInitializedorDisabledand start a second replay for the same dedup cursor. - There's also a retry gap: if enabling fails transiently, the status moves to
Failedbut later checks don't retry.
Let me find the relevant file(s).
Assistant
The main file is
MessageDeduplication.java. Let me open it.Assistant
Let me use the bash terminal to open the file using the
opencommand.Assistant
Let me look at the relevant methods. Let me search for
checkStatusandRecovering.Assistant
Let me look at the checkStatus method more closely:
Assistant
Now I can see the issue. Let me look at the test file for more context:
Assistant
Now I understand the issue clearly. Let me look at the exact lines I need to modify
Assistant
Now I'll make the fix. The issue has three parts:
- Set
status = Status.Recoveringbefore starting the async enable - so that concurrentcheckStatus()calls seeRecoveringand bail out - On failure, set status back to
Disabledinstead ofFailed- so that a latercheckStatus()call can retry enabling
Let me apply the fix
- Set
Assistant
Let me apply the changes properly using the
editcommandAssistant
Let me use sed to make the changes
Assistant
Now change
Status.FailedtoStatus.Disabledin the exception handlerAssistant
Let me verify the changes look correct
Assistant
The changes look correct. Let me verify there are no other references to
Status.Failedthat need updating, and run the relevantAssistant
No remaining references to
Status.Failed. The enum value still exists but is no longer used, which is fine. Let me run the relevant testsAssistant
Let me find the correct module path
Assistant
Let me look at the directory structure.
Assistant
Hmm, the output seems empty. Let me try a different approach.
Assistant
It seems the find command is not showing anything. The output is empty. Let me try ls.
Assistant
This is a Gradle project. Let me compile the code to verify correctness.
Assistant
Build successful. Now let me run the relevant tests.
Assistant
Tests pass. Let me also run the other related deduplication tests.
Assistant
Let me also run the BrokerMessageDeduplicationTest
Assistant
All tests pass. Let me verify the final state of the changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.