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
I'll start by exploring the repository structure and locating the MessageDeduplication-related code to understand the recovery race.
- Assistant
I'll inspect
MessageDeduplicationand related tests, focusing on status transitions and the enable/recovery path. - Assistant
Let me look at the checkStatus method which seems to be the core of the issue.
- Assistant
Let me read the full checkStatus method and related code.
- Assistant
Let me continue reading the checkStatus method, especially the enable path.
- Assistant
I'll finish reading the enable path recovery completion, then scan nearby tests for the expected pattern.
- Assistant
I'll read the existing dedup unit test and any git history around the recover status change.
- Assistant
I'll check git history for the enable path of checkStatus and read the rest of the failing status test.
- Assistant
Checking how the original enable path set Recovering, and whether PR #25953 is available locally.
- Assistant
I'll fix the enable path: set status to Recovering first, and allow retry from Failed.
- Assistant
I need to navigate to that line before editing.
- Assistant
Now I can apply the edit.
- Assistant
I'll inspect
openCursorand craft a temporary reproduction to verify the race and the fix. - Assistant
I'll write a temporary reproduction test and run it with the project's test tooling.
- Assistant
I'll run the existing
BrokerMessageDeduplicationTestto make sure the Failed path still works after the change. - Assistant
Checking whether the test run succeeded.
- Assistant
Forcing a clean recompile and re-run of the test.
- Assistant
I'll add a temporary verification method to confirm the race is fixed, then remove it.
- Assistant
I'll get the test classpath and run the temporary reproduction.
- Assistant
Let me fix the init script and get classpath.
- Assistant
Compiling and running the race reproduction against the fixed code.
- Assistant
I'll put the repro in the same package so it can access
Status. - Assistant
Verifying the pre-fix code fails the race to confirm we reproduced the bug.
- Assistant
Re-running the race check against the original code more carefully.
- Assistant
Confirmed the original code raced (two opens, never Recovering). Cleaning uptemps and reviewing the final diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.