GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@namest504 namest504 commented Oct 23, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

  • PartitionedProducerImpl: after scheduling the partition update timer, cancel it if the producer has already reached a terminal state after start(); and in the timer task, reschedule only while the producer is not in a terminal state. isTerminalState() comes from ProducerBase ([fix][client] Close the producer when its encryption key cannot be loaded #27024).

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.

All reactions
@namest504
Stop the partition update timer of a partitioned producer that ended …
a6814c6
…during creation
codelipenghui
codelipenghui approved these changes Oct 23, 2026
View reviewed changes

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
@namest504 namest504 mentioned this pull request Oct 23, 2026
[fix][client] Flush the pending acks before the flow command when the consumer reconnects #27062
Merged
2 of 5 tasks
@namest504
Cancel the partition update timer after scheduling it when the produc…
932aff9
…er already ended
@namest504

namest504 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@namest504
Shorten the comments on the partition update timer
b1c8338
codelipenghui
codelipenghui approved these changes Oct 23, 2026
View reviewed changes

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
@merlimat merlimat added this to the 5.1.0 milestone Oct 23, 2026
@merlimat merlimat added the release/5.0.2 label Oct 23, 2026
@merlimat
merlimat merged commit d51ff7a into apache:master Oct 23, 2026
43 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@namest504
namest504 deleted the fix/partitioned-producer-timer-after-failed-creation branch October 24, 2026 04:09
lhotari pushed a commit that referenced this pull request Oct 26, 2026
@namest504 @lhotari
[fix][client] Stop the partition update timer of a partitioned produc…
f00ff82
…er that ended during creation (#27061)

(cherry picked from commit d51ff7a)
@lhotari lhotari added the cherry-picked/branch-5.0 label Oct 26, 2026
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
@lhotari lhotari added cherry-picked/branch-4.2 release/4.2.6 cherry-picked/branch-4.0 release/4.0.15 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@namest504 @lhotari
[fix][client] Stop the partition update timer of a partitioned produc…
c50d694
…er that ended during creation (apache#27061)

(cherry picked from commit d51ff7a)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@namest504 @lhotari
[fix][client] Stop the partition update timer of a partitioned produc…
b5aec50
…er that ended during creation (apache#27061)

(cherry picked from commit d51ff7a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@codelipenghui codelipenghui codelipenghui approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 release/4.0.15 release/4.2.6 release/5.0.2

Projects

None yet

Milestone

5.1.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@namest504 @codelipenghui @merlimat @lhotari
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.