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 inspect the deduplication state machine and its focused tests, then patch the transition/retry behavior and run the narrowest relevant test suite. I’ll follow the repository’s Java/concurrency guidance; no external sources are needed.
- Assistant
rgis unavailable in this checkout, so I’m switching tofind/grep. The relevant guidance confirms this needs deterministic async coverage, including the failure-to-retry path. - Assistant
The race is localized: the enable branch opens the cursor while still exposing
Initialized/Disabled. I’m changing that branch to claimRecoveringunder the existing synchronization lock, and makingFailedeligible for a policy-required retry. The tests will hold cursor-open completion to prove a second check cannot open it again, then inject a transient open failure to prove the next check retries. - Assistant
The implementation and two regression tests are in place. The focused broker test is compiling/running now; I’m checking both behavioral coverage and style rather than relying on the state transition alone.
- Assistant
The first Gradle invocation is spending an unusually long time in task-graph/configuration setup without test output. I’m checking whether it is still making progress; if necessary I’ll correct compile feedback and rerun with the warmed configuration cache.
- Assistant
Gradle is blocked trying to resolve build metadata over the network, which is outside this task’s constraints. I’m stopping that attempt and rerunning offline against the repository’s local dependency cache; this should surface compile/test results without external access.
- Assistant
Offline resolution is working, but the broker test graph includes an unrelated Pulsar IO data-generator module whose
jfairydependency is not cached. I’m separating implementation compilation/style checks from the test run and will attempt the focused test with those unrelated generator tasks excluded if the broker test classpath permits it. - Assistant
The focused test now passes offline: all 5 tests in
BrokerMessageDeduplicationTest, including both new regressions, completed with zero failures. Main and test sources also compile; I’m doing the final diff/style validation now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.