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
Now let's edit the checkStatus method to fix the race and retry-on-Failed issue.
Assistant
Now let's use the
editcommand with proper syntax227:237.Assistant
This resolves both issues from the report:
- Status now transitions to
Recoveringbefore starting the async cursor open/replay, so concurrentcheckStatus()calls will hit theRecoveringbranch and schedule a retry instead of starting another replay. - The enable branch now also triggers from
Status.Failed, enabling retry after a transient failure.
Let's verify the whole file compiles and check existing tests related to MessageDeduplication.
- Status now transitions to
Assistant
Let's build and run this test to make sure the fix compiles and works.
Assistant
Good, gradle wrapper works. Let's try running the specific test.
Assistant
Tests pass. Now let's write a quick reproduction test to verify the race is fixed, then remove it before submitting.
Assistant
The custom repro test passed, confirming the fix. Let's verify it would have failed before the fix by reverting temporarily.
Assistant
Confirmed the test fails without the fix (2 cursor opens instead of 1). Now restore the fix.
Assistant
Now let's re-run the test with fix applied to confirm it passes again, then remove the temp test file (per instructions not to add new tests to the repo).
Assistant
Now remove the temporary test file since we shouldn't add new tests to the repo.
Assistant
Now let's run the existing test suite for BrokerMessageDeduplicationTest again to confirm everything still passes with the final state.
Assistant
Let's view the final diff to confirm the changes are clean.
Assistant
No conflicts elsewhere. Let's run broader related tests (dedup-related integration tests) to be safe.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.