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 trace
MessageDeduplication, its status transitions, and existing tests first. Then I’ll make the smallest state-machine change, add no repository tests per instruction, and run the focused existing test suite plus compilation checks. - Assistant
rgis unavailable in this environment, so I’ll usegrep/findto locate the implementation and call sites. - Assistant
The race is confirmed in
checkStatus(): the enable branch constructs the asynchronous replay while leaving status unchanged. I’ll setRecoveringinside the existing synchronized section before opening the cursor, and includeFailedin the retryable enable states when policy still requires deduplication. I’ll inspect related lifecycle methods and test module details before editing. - Assistant
There are no focused
MessageDeduplicationunit tests in the repository; the relevant coverage is integration-oriented. The transition is guarded bysynchronized (this), so assigningRecoveringbefore launchingopenCursoris sufficient to make subsequent checks take the in-progress path. I’ll now apply that change and addFailedonly to the enable condition. - Assistant
Python is also unavailable, so I’ll use the repository’s
editcommand with the exact line range. - Assistant
The code now marks recovery atomically before asynchronous cursor work and retries from
Failedwhen enabled. I’ll run formatting/style checks and the broker tests most likely to exercise deduplication. First I’ll inspect the project’s Maven wrapper and test naming. - Assistant
The repository uses Gradle. The diff is whitespace-clean and only changes the intended production file. I’ll run broker Java compilation first, then the existing
BrokerMessageDeduplicationTestif compilation succeeds. - Assistant
The first compile command had an accidental non-ASCII shell variable appended, so Bash rejected the command before running Gradle. I’ll rerun it cleanly.
- Assistant
Broker compilation passes. I’ll run the existing broker deduplication test class; this is the closest available regression coverage without modifying tests.
- Assistant
The focused
BrokerMessageDeduplicationTestpasses, and compilation passes. The implementation also handles transient enable failure: the failure callback leavesFailed, and a later check with deduplication still required now re-enters recovery. I’ll perform a final diff/status review and then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.