Untitled conversation
- User
[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
Now I'll implement the fix in
checkStatus(): - Assistant
Now add the missing
CompletableFutureimport to the test: - Assistant
While the tests run, let me re-verify the final state of the fixed
checkStatus()block: - Assistant
Let me check the existing tests that exercise
checkStatus()failure behavior, since my change altersFailedhandling: - Assistant
Existing tests remain compatible:
checkStatusFailstill ends inFailedwith the future completing exceptionally. Let me check on the background test run: - Assistant
Now update the first test to match the improved semantics (the concurrent caller gets the in-flight future):
- Assistant
No subclasses. Waiting for the first test run to complete before rerunning with the final code.
- Assistant
I'll wait for the build to finish — the monitors will notify when there's output.
- Assistant
The build is still in its first cold run (fresh workspace, compiling the whole dependency graph). The background waiter
b7cf73t6mwill notify when it produces output. Since my later edits may or may not have been picked up mid-build, I'll rerun the tests after this run completes — the rerun will be fast with warm caches. Waiting now. - Assistant
Rerun launched. Once it completes, I'll also run checkstyle on the module. Waiting for the notification.
- Assistant
All 5 tests pass. Now run the lint checks:
- Assistant
Waiting for the lint run to complete.
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.