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. - Assistant
I’ll trace the deduplication state machine and its focused tests, then patch the transition/retry logic and run the narrowest relevant test suite. I’ll follow the repository’s concurrency and test guidance in
CODING.md. - Assistant
rgis unavailable in this checkout environment, so I’m switching tofind/grepand keeping the inspection scoped to broker deduplication code. - Assistant
The enable branch confirms both reported gaps: it starts
openCursor(...).thenCompose(replayCursor)while leaving the status unchanged, and its eligibility excludesFailed. I’m adding the transition before any async work and focused tests that hold the first cursor-open callback to prove a second check cannot open again, plus a retry assertion after failure. - Assistant
The patch is now in place and passes whitespace validation. The regression test explicitly delays the first cursor open, calls
checkStatus()again, and verifies only one open occurred; the retry test makes the first open fail and the second succeed. I’m compiling/running that test class now. - Assistant
Gradle is still configuring the large broker task graph and has not emitted compile/test output yet. The process remains active; I’ll keep it running and address any compile or behavioral failure it surfaces.
- Assistant
The focused run is unusually quiet but still alive after configuration began—there is no failure output or dependency prompt. I’m allowing the initial Gradle configuration a little more time, then I’ll inspect the process if it remains silent.
- Assistant
Process inspection shows the Gradle daemon is actively using CPU, so it is progressing through configuration rather than hung. I’m continuing the run; this appears to be cold-build overhead for the repository.
- Assistant
The thread dump revealed Gradle is waiting on an HTTP dependency lookup during task-graph calculation. Since this task must remain offline, I’m stopping that attempt and rerunning in Gradle offline mode so verification uses only the repository’s local cache and fails promptly if an artifact is absent.
- Assistant
Offline mode exposed a missing cached artifact in an unrelated Pulsar IO module while serializing the configuration cache. I’m disabling configuration-cache serialization for the same focused broker test; that should avoid resolving unrelated module classpaths.
- Assistant
Even without configuration caching, the broker test graph eagerly compiles unrelated IO generator projects whose sole missing artifact is
jfairy. I’ll make one offline attempt excluding those unrelated compile tasks; this preserves compilation and execution of the broker and its actual dependencies. - Assistant
The focused broker test now compiles and passes offline. The successful run exercised all tests in
BrokerMessageDeduplicationTest, including the delayed-recovery race and transient-failure retry; I’m doing a final diff/status check to ensure only the intended source and test changes remain.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.