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 trace the enable/failure transitions before making a minimal concurrency-safe change.
- Assistant
rgis unavailable in this checkout, so I’ll usefind/grepto identify the implementation and related tests. - Assistant
I found the implementation and focused tests. Next I’ll inspect the full transition logic and test conventions, especially how asynchronous recovery completion updates status.
- Assistant
The defect is visible: the enable branch starts
openCursor(...).thenCompose(...)while leaving status unchanged, and its eligibility excludesFailed. I’ll inspect history/remotes and all status references to ensure the fix matches established semantics and does not conflict with other transitions. - Assistant
A minimal state-machine correction is appropriate: atomically set
Recoveringinside the synchronized enable decision, and permit the same branch fromFailedwhen policy still requires deduplication. This blocks duplicate replay starts while preserving the existing delayed recheck behavior. I’ll apply that source-only change (without altering tests, per instructions). - Assistant
Python is also unavailable, so I’ll use the repository editor command to make the exact replacement and immediately inspect the diff.
- Assistant
The editor located the target but requires it in the displayed window. I’ll open that section, then apply the replacement.
- Assistant
The target is now in view; I’ll edit the enable condition and transition.
- Assistant
The diff now implements both required transitions. Before running tests, I’ll inspect the focused test class setup and build configuration to choose the narrowest viable Maven invocation and determine whether an existing test exercises policy toggling/recovery.
- Assistant
This checkout uses Gradle rather than Maven. The focused unit class already covers failed recovery, though not retry; I’ll identify the broker test task syntax and then run just this class.
- Assistant
Gradle configuration exceeds the terminal call timeout. I’ll launch the single-class test in the background, then poll its log/process so it can complete without being killed by the command interface timeout.
- Assistant
The focused test is running as PID 357. I’ll poll its status and inspect the latest output for compilation or test failures.
- Assistant
Gradle downloaded successfully and is configuring the task graph. I’ll continue polling until the focused test completes.
- Assistant
Configuration is still in progress with no errors reported. I’ll give it more time and check both the process tree and log.
- Assistant
The Gradle process remains active (likely first-run Kotlin configuration). I’ll wait longer; meanwhile, the source diff is formatting-clean and localized to the state transition.
- Assistant
Build-logic tasks are now progressing normally. I’ll continue polling for the broker compilation and TestNG result.
- Assistant
Gradle’s initial convention-plugin compilation is continuing without failures. I’ll allow it to finish rather than interrupting the verification.
- Assistant
Convention plugins have compiled; the next phase should configure and compile the selected broker test. I’ll poll again.
- Assistant
The process is still active during project configuration and has emitted no error. I’ll check resource/process state and continue waiting.
- Assistant
The focused task is compiling its required dependency graph and is actively using CPU; this is expected for a clean Pulsar build. I’ll keep it running to obtain a definitive result.
- Assistant
The modified broker source compiled successfully; only unrelated existing warnings were emitted. I’ll poll once more for test execution completion.
- Assistant
Gradle is compiling the broker test sources (despite the class filter); the warnings are pre-existing and unrelated. I’ll wait for TestNG to finish.
- Assistant
The focused test task reports
BUILD SUCCESSFULafter compiling and runningBrokerMessageDeduplicationTest. The wrapper subshell was job-control-stopped after Gradle exited, before recording its exit marker; I’ll resume/clean it, verify test reports and repository state, and inspect the final diff. - Assistant
Verification shows all 3 focused tests passed with zero failures,
git diff --checkis clean, and only the intended source file changed. As a final style safeguard, I’ll run the broker Java formatting check using the now-warm Gradle configuration. - Assistant
The formatting check is running in the background; I’ll poll its result.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.