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 locate the deduplication state machine and its tests, then inspect the enable/recovery transitions and existing concurrency coverage before making the smallest state-transition fix.
- Assistant
rgis unavailable, so I’ll usefind/grepto identify the implementation and relevant test classes. - Assistant
I found the core class. I’ll read the full state machine and search for direct tests of
checkStatus, enablement, and failure handling to preserve established semantics. - Assistant
The defect is visible: the enable branch neither sets
Recoveringnor includesFailedas retryable. I’ll inspect the focused broker test and repository history/remotes in case the referenced upstream fix or exact expected semantics are available locally. - Assistant
The intended change is narrowly scoped: treat
Failedas an enable candidate when policy requires deduplication, and assignRecoveringwhile still inside the synchronized block before opening the cursor. That atomic transition ensures every later check takes the existing “transition in progress” path instead of launching another replay. I’ll apply that fix without altering tests. - Assistant
Python is also unavailable. I’ll use the repository editor command to make the same targeted replacement, then inspect whitespace and the resulting diff.
- Assistant
The editor requires the target region to be open despite receiving a file path. I’ll open that section and retry the exact replacement.
- Assistant
The diff now exactly implements the two requested state-machine behaviors. I’ll run the focused
BrokerMessageDeduplicationTest, which already exercises asynchronous enable failure, to verify compilation and failure propagation with the newRecoveringtransition. - Assistant
There is no Maven wrapper or root
pom.xmlin this checkout layout. I’ll inspect the root and module metadata to identify the project’s actual build entry point rather than assuming Maven. - Assistant
This branch has migrated to Gradle. I’ll invoke the module’s test task with a class filter for the focused test.
- Assistant
The focused test suite passed, including asynchronous replay failure propagation. The implementation also satisfies the deterministic race scenario by construction: the first call sets the volatile status to
Recoveringunder the same monitor used by the second call, so only one cursor open can be initiated; a failed future resets status toFailed, which is now eligible on the next policy check. I’ll perform final diff/status checks and ensure no build artifacts are tracked.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.