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
Now let me check the helpers used by the enable path:
- Assistant
Now I'll apply the fix to
checkStatus(): - Assistant
Now check
ManagedLedgerReplayTask.replayto know what the cursor mock needs for the test: - Assistant
Now run the new tests. Check the build setup first:
- Assistant
The background test run will notify when it completes. Waiting on that.
- Assistant
Still compiling. I'll report back when the test run finishes.
- Assistant
The output is piped through
tail -40, so nothing appears until Gradle finishes. Both the background task and the monitor will fire on completion — waiting. - Assistant
Still compiling. Both watchers will notify me when the run finishes — standing by.
- Assistant
The build is still in early stages (dependency resolution/compiling upstream modules). I'll stop polling and wait for the monitor notification.
- Assistant
Nothing new to do until the test run completes. The background task (b0vzyvj05) and monitor (be6gn637d) will both notify on completion.
- Assistant
Standard configuration — the build simply hasn't reached compilation output yet. Waiting for the completion notification now.
- Assistant
Waiting on the Gradle run (task b0vzyvj05); the monitor will fire when it finishes.
- Assistant
12 minutes in with no compiled output — let me check the Gradle daemon log for what it's actually doing:
- Assistant
Offline run started in the background. Waiting for it to complete.
- Assistant
Waiting on the offline Gradle run (task b7ovxyhbr).
- Assistant
pulsar-broker's test task pulls inpulsar-io-data-generator, which needs an uncached dep (jfairy). Let me check if network is available at all: - Assistant
Network works via curl — the earlier hang was likely the JVM preferring IPv6. Retry online with IPv4 forced:
- Assistant
Waiting for this run (bk6hk8yda) to complete.
- Assistant
High CPU — it's compiling now. Waiting for completion.
- Assistant
Waiting on test execution.
- Assistant
Still running. Waiting for the background-task notification.
- Assistant
Waiting on the Gradle run to finish.
- Assistant
Everything compiled cleanly, including the new test. Test execution is next — waiting.
- Assistant
Waiting on the Gradle run (bk6hk8yda).
- Assistant
Let me check what the build is doing right now:
- Assistant
An active daemon is at 189% CPU — build is progressing. Waiting for the completion notification.
- Assistant
Build still running. I'll wait for the background notification before checking again.
- Assistant
Build in progress (~3 min in). I'll stop polling — the completion notification for task bk6hk8yda will trigger the next check.
- Assistant
The test task is now executing (results dir appeared). Waiting for it to finish.
- Assistant
BUILD SUCCESSFUL. Verify both test classes actually ran and passed:
- Assistant
Both suites pass (5/5). Now run the integration test that exercises
checkStatus()end-to-end, plus lint on the changed module: - Assistant
Still waiting — integration tests start an embedded broker and take several minutes.
- Assistant
Still running — waiting for completion.
- Assistant
Waiting for the run to complete (bcxx1hixz).
- Assistant
That was just the stale monitor from the first killed run timing out — ignorable. Still waiting on the checkstyle/integration build (bcxx1hixz).
- Assistant
Checkstyle is running. Waiting for completion.
- Assistant
Waiting for the final build notification.
- Assistant
Still waiting.
- Assistant
Checkstyle still processing (73% CPU). Waiting.
- Assistant
Waiting — checkstyle hasn't emitted reports yet.
- Assistant
Still waiting.
- Assistant
Build still active. Waiting for the notification.
- Assistant
Checkstyle workers just spun up. Should finish shortly.
- Assistant
All green. Final state of the change:
- Assistant
Done. Summary of the fix for the dedup recovery race:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.