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 in this environment, so I’ll use recursivegrepto find the implementation and tests. - Assistant
I found the implementation and focused tests. I’ll read the complete state-related methods and test setup to understand intended status semantics, synchronization, and failure handling.
- Assistant
The bug is visible: the enable branch neither marks
Recoveringnor admitsFailedfor retry. The direct fix is to setRecoveringwhile holding the existing monitor, before opening the cursor, and includeFailedin the enable predicate. I’ll inspect nearby history/style and the replay utility’s async behavior to ensure exception propagation does not introduce an invalid transition. - Assistant
I’ll inspect the file’s earlier state-machine changes and repository status, then patch only production code. Per the constraints, I will not add or alter tests; I can use the existing failure test plus a temporary standalone check if needed.
- Assistant
The monitor makes the transition atomic once
status = Recoveringis added. IncludingFailedonly when policy says enabled provides the requested retry while preserving behavior after a failed disable when policy remains disabled. I’ll apply those two state-machine changes. - Assistant
Python is also unavailable, so I’ll use the repository editor command to perform the same targeted replacement and then inspect the diff.
- Assistant
The diff is minimal and formatting-clean. The existing
checkStatusFailtest directly exercises recovery failure and will also verify that the newRecoveringstate still transitions toFailed; I’ll run that test class first, then assess whether a broader focused test class is affordable. - Assistant
There is no Maven wrapper. I’ll identify the available build tooling and Java/Maven installation, then invoke the same targeted test with the repository’s supported command.
- Assistant
This checkout uses Gradle rather than Maven. I’ll inspect its documented module/test task conventions and locate the broker project path before running the focused TestNG class.
- Assistant
The documented convention is Gradle
--tests. I’ll run the exact broker unit-test class now. - Assistant
The focused unit class passed, including the existing asynchronous recovery-failure case. To cover policy-driven enable/disable integration behavior around
checkStatus(), I’ll also runTopicDuplicationTest, which contains repeated policy transitions and explicit status checks. - Assistant
Both focused suites pass. I’ll perform the final repository checks: ensure only the intended production file changed, verify whitespace, and inspect the final diff. This also confirms no test files or generated artifacts are being submitted.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.