GeezerVison is showing github.com — [fix][client] Stop the partition update timer of a partitioned producer that ended during creation by namest504 · Pull Request #27061 · apache/pulsar
Conversation
namest504
commented
Oct 23, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Motivation
Follow-up to #27024, from the review there.
PartitionedProducerImpl schedules the partition update timer at the end of its constructor, after start(). When the first partition's creation ends inside start(), which a connection that fails at once with a non-retriable error or a key that cannot be loaded causes, the producer has already closed itself before that line runs. The close found no timer to cancel, and the constructor then schedules one. The timer task returns early when the state is not Ready, but the return is inside a try whose finally reschedules the task unconditionally, so a timer that was cancelled or that belongs to a closed producer keeps rescheduling itself. Each failed create() on a partitioned topic leaves a recurring task that keeps the closed producer and its partition producers reachable.
Modifications
The timer is stored before the state is checked, and closeAsync() sets the state before it reads the timer, so when start() ends the producer on another thread one of the two always cancels it.
Verifying this change
- Make sure that the change passes the CI checks.
New tests in PartitionedProducerImplTest, both failing before the change:
testPartitionUpdateTimerIsCancelledWhenTheCreationEndsInTheConstructor: a first partition whose connection fails at once ends the creation inside the constructor; the partition update timer scheduled afterwards is cancelled (before: left running).
testPartitionUpdateTimerStopsOnceTheProducerEnded: a producer still being created schedules the task; after it closes, running the task does not reschedule it (before: 2 tasks after one run).
PartitionedProducerImplTest and PartitionedProducerConsumerTest pass.
Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API: no
- The schema: no
- The default values of configurations: no
- The threading model: no
- The binary protocol: no
- The REST endpoints: no
- The admin CLI options: no
- The metrics: no
- Anything that affects deployment: no
Documentation
-
doc-required
-
doc-not-needed
-
doc
-
doc-complete
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed head a6814c634b032b6906b83ead31e79759226287a3. LGTM.
Both guards fix the leak. Skipping the schedule when the producer is already terminal after start() covers a creation that ends inside the constructor. Re-arming only while the producer is not terminal also stops a stray timer when an ordinary close runs while the task is running. Stopping in terminal states is safe: PartitionedProducerImpl never goes from Failed, Closing or Closed back to Ready, and while creation is still running the task keeps re-arming as before.
Validation: PartitionedProducerImplTest passes (12 tests). With both guards reverted, both new tests fail (expected [0] but found [1] and expected [1] but found [2]), so they reproduce the problem.
Before merging: CI - Unit - Brokers - Client Impl failed on this head. I couldn't see its logs, so please check it or re-run it. From the code it doesn't look related, but I couldn't confirm that.
Optional, non-blocking: you can close the remaining window you describe without a lock. Publish the timeout first, then cancel it if isTerminalState(), as ProducerImpl.scheduleKeyGeneratorTask() does. closeAsync() sets Closing before it reads the field, and both are volatile, so one side always cancels the timer. Fine to leave as is, since the timer now stops after one run.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks. The Brokers - Client Impl failure is ConsumerDedupPermitsUpdateTest#testConsumerDedup, which fails on master since #21928: the flush of the pending acks after the reconnect runs after the flow command, so the broker redelivers the messages whose acks are still in flight and the client has already dropped them from the pending acks it checks for duplicates. #27062 moves the flush before the flow command; with it the test passes 5 runs out of 5 here (before: 4 of 5 fail on master).
I took the suggestion in 932aff9: the timer is scheduled and then cancelled if the producer is already terminal, and the test checks the cancellation instead of the absence of the timer.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-reviewed at head b1c833858aa7b1f334123fb901bd2e79b8f0ee66. LGTM.
932aff9 closes the remaining window in the constructor. The timer is stored before the state is checked, and closeAsync() sets Closing before it reads the field, so one of the two always cancels it. The re-arm guard in the timer task is unchanged.
Validation: PartitionedProducerImplTest passes (12 tests). With the re-check disabled, testPartitionUpdateTimerIsCancelledWhenTheCreationEndsInTheConstructor fails (Wanted but not invoked: timeout.cancel()). I also ran a temporary test that fails the first partition between newTimeout and storing the field: it passes with the re-check and fails without it. CI is green on this head, including Brokers - Client Impl.
Thanks for the follow-up.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 21, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|