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 issue. The problem is in
MessageDeduplicationwhere:- Dedup recovery can be started multiple times before the first recovery completes because the status isn't set to
Recoveringbefore starting the async replay. - After a failure, the status moves to
Failed, but later checks don't retry enabling.
Let me explore the repository structure and find the relevant file(s).
- Dedup recovery can be started multiple times before the first recovery completes because the status isn't set to
Assistant
Let me look at the main
MessageDeduplication.javafile first.Assistant
Let me scroll through the file to understand the key methods:
Assistant
Let me read the core logic more carefully, especially around
checkStatusand the enable/disable pathsAssistant
Let me use
gototo navigate to line 156 and then scroll down.Assistant
Now let me see the
replayCursormethod:Assistant
Let me read the
replayCursormethod from line 245 onwards.Assistant
Now I have a clear picture of the issues. Let me look at the exact lines I need to modify:
-
Race condition: On line 227-229, the enable path doesn't set status to
Recoveringbefore starting async operations. AnothercheckStatus()call can observeDisabled/Initializedand start a second recovery. -
Failed status doesn't retry: Line 227 only checks
DisabledorInitializedbut notFailed, so aFailedstatus never retries.
Let me apply the fixes
-
Assistant
Good. Now let me verify the changes look correct by viewing the full
checkStatusmethodAssistant
I notice the
return future;line is missing from the enable path. Let me add it backAssistant
The changes look good. Let me verify with
git diffand then run the relevantAssistant
The diff looks correct. Now let me find and run the relevant tests to make sure nothing is broken.
Assistant
Let me find more specific test files related to deduplication:
Assistant
Let me first try to compile the project to check for compilation errors, and then run the most relevant tests.
Assistant
Let me find the correct module name.
Assistant
Let me look at the directory structure more carefully.
Assistant
This is a Gradle project. Let me try compiling.
Assistant
Compilation succeeds. Let me now run the relevant test classes to ensure my changes don't break anything
Assistant
Tests pass. Let me also quickly 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.