Untitled conversation
- User
[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.Error messages
- Assistant
I’ll trace the deduplication state machine and its tests, then patch the transition/retry behavior and run the narrowest relevant test suite. I’ll follow the repository’s concurrency and Java testing guidance.
- Assistant
The defect is localized: the enable branch launches
openCursor(...).thenCompose(replayCursor)while leaving the state unchanged, and its eligibility excludesFailed. I’m checking the cursor helper and existing test mechanics now so the regression tests delay the real async boundary instead of mutating private state. - Assistant
The implementation now marks the state
Recoveringinside the synchronized enable decision, before cursor opening begins, and treatsFailedas eligible for a later enable attempt. The focused tests cover both a held-open recovery (only one cursor open is permitted) and a transient cursor-open failure followed by a successful retry. - Assistant
The first Gradle invocation stalled while attempting dependency resolution, so I stopped it to honor the no-internet constraint. I’m rerunning in offline mode; if the local cache is incomplete, I’ll report that limitation separately from source-level verification.
- Assistant
Offline configuration is workable, but the broker test graph includes optional data-generator modules whose uncached
jfairydependency blocks the build before broker tests run. I’m excluding only those unrelated compile tasks for this focused test; the deduplication test does not use those connectors. - Assistant
The focused regression class now compiles and passes offline. I’m doing the final style/static checks and reviewing the diff for accidental scope changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.