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 finding the relevant file(s) related to the issue. The issue mentions
MessageDeduplicationandcheckDeduplicationStatus(). Let me explore the codebase.Assistant
Let me look at the main
MessageDeduplication.javafile first.Assistant
Let me try the open command differently.
Assistant
Let me search for the key methods in the file.
Assistant
Let me look at the
checkStatus()method and the enable path inAssistant
Let me use scroll_down to view the relevant sections.
Assistant
Let me continue viewing the file.
Assistant
Let me also check how
checkDeduplicationStatusis called fromBrokerService.javaand `PersistentTopic.javaAssistant
Let me look at PersistentTopic.java for
checkDeduplicationStatus.Assistant
Let me look at the checkDeduplicationStatus method in PersistentTopic.java.
Assistant
Now I have a clear understanding of the issues. Let me also check the existing tests to understand the expected behavior better
Assistant
Let me view the full checkStatus method one more time carefully
Assistant
Now I fully understand the issues. Let me summarize them and implement the fixes:
Issues found:
Recoveringstatus never set before async recovery - Line 227-237: When enabling dedup, the code callsopenCursorandreplayCursorbut never setsstatus = Status.Recovering, so anothercheckStatus()can enter the same enable path.Failedstatus never retried - Whenstatus == Status.FailedandshouldBeEnabledis true, it falls to the else branch and does nothing.- Bug:
future.completeExceptionally(e)on already-completed future - Line 234 callscompleteExceptionallyon a future that already completed exceptionally.
Let me apply the fix:
Assistant
Good. Let me verify the complete
checkStatus()method to make sure it's correct.Assistant
The changes look correct. Let me now verify the code compiles by looking at the build system.
Assistant
Let me find the correct module name.
Assistant
Maybe the directory structure is different. Let me check.
Assistant
Let me check the build system.
Assistant
Let me check if there's a gradlew script available.
Assistant
Let me check the module structure.
Assistant
Let me search for any other references to the
Recoveringstatus to make sure my change is consistent.Assistant
Now let me look at existing tests and try to compile just to verify syntax.
Assistant
Let me look at the
BrokerMessageDeduplicationTest.javato understand the existing tests for checkStatus:Assistant
Let me try to compile the project using gradle to verify the syntax is correct.
Assistant
The build succeeds. Let me now run the relevant unit tests to verify nothing is broken.
Assistant
Let me also run the other relevant tests
Assistant
Let me also run the remaining deduplication-related tests:
Assistant
Let me verify the final state of the changes once more:
Assistant
The changes look correct. Let me verify by reviewing the complete modified method one last time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.