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][ml] Fail in-flight adds when a managed ledger is terminated by merlimat · Pull Request #26678 · apache/pulsar

Conversation

@merlimat

@merlimat merlimat commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Motivation

Terminating a managed ledger closes the current BookKeeper ledger, and that close errors out the adds that are still in flight (LedgerHandle.doAsyncCloseInternal fails every un-acked pending add with LedgerClosedException). OpAddEntry.handleAddFailure hands those adds to ManagedLedgerImpl.ledgerClosed(), which had no branch for the Terminated state and returned without touching them, so they were never completed nor failed.

In the broker this leaks PersistentTopic.pendingWriteOps. Any publish that reaches the terminated ledger fails with ManagedLedgerTerminatedException, which fences the topic, and the topic is only unfenced once the pending writes drain to zero. With the leaked ops that never happens, so the topic stayed fenced forever and every subscribe was rejected with Topic is temporarily unavailable (topicFencingTimeoutSeconds is 0 by default, so nothing force-closes it either).

Scalable topics seal segments by terminating them, routinely and under producer load, so this was hit easily: a v5 StreamConsumer that must drain a sealed segment before its children are handed out could never subscribe to the fenced segment and stopped making progress. The broker log shows repeated Attempting to subscribe to a fenced topic for the sealed segment://... topic.

Modifications

  • ManagedLedgerImpl.ledgerClosed(): when the ledger is closed in the Terminated state, fail the pending adds with ManagedLedgerTerminatedException, as is already done for the Closed and Fenced states. No new ledger will ever be created to retry them.

Verifying this change

This change added tests and can be verified as follows:

  • ManagedLedgerBkTest.testTerminateFailsInFlightAdds (real bookies): suspends the bookie so an add stays in flight, terminates the ledger, and asserts the add fails with ManagedLedgerTerminatedException. Before the fix the add callback never fires.
  • BrokerBkEnsemblesTest.testConsumerCanSubscribeAfterTerminateWithInFlightPublish: delays the bookie response so a publish is in flight when PersistentTopic.terminate() runs, sends one more publish to the terminated topic, and asserts the pending write count drains and a consumer can subscribe. Before the fix the count stays at 1 and the subscribe fails with Topic is temporarily unavailable.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Sorry, something went wrong.

Uh oh!

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

All reactions
@merlimat
[fix][ml] Fail in-flight adds when a managed ledger is terminated
21ce72a
Terminating a managed ledger closes the current BookKeeper ledger, and the
close errors out the adds that are still in flight. Those adds were handed to
ledgerClosed(), which had no branch for the Terminated state and returned
without touching them, so they were never completed nor failed.

In the broker this leaks PersistentTopic.pendingWriteOps. Any publish that
reaches the terminated ledger fences the topic, and the topic is only unfenced
once the pending writes drain to zero, so it stayed fenced forever and rejected
every subscribe with "Topic is temporarily unavailable". Scalable topics seal
segments by terminating them under producer load, so a stream consumer that
has to drain the sealed segment could never attach and stopped making progress.

Fail the pending adds with ManagedLedgerTerminatedException when the ledger is
closed in the Terminated state, as already done for the Closed and Fenced
states.
@merlimat merlimat mentioned this pull request Sep 21, 2026
[fix][ml] Fail queued adds when a managed ledger is terminated during a ledger rollover #26680
Merged
10 tasks
nodece
nodece approved these changes Sep 22, 2026
View reviewed changes
dao-jun
dao-jun approved these changes Sep 22, 2026
View reviewed changes
@dao-jun dao-jun added release/4.0.14 release/4.2.5 labels Sep 22, 2026
@dao-jun dao-jun added this to the 5.0.0 milestone Sep 22, 2026
lhotari
lhotari approved these changes Sep 22, 2026
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

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.

LGTM. Thanks for fixing this termination race. The terminal-state branch now completes pending adds with the expected exception, and the managed-ledger and broker regression coverage verifies both callback completion and topic unfencing.

Sorry, something went wrong.

Uh oh!

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

All reactions
@merlimat
merlimat merged commit a521e68 into apache:master Sep 22, 2026
44 checks passed

Uh oh!

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

@merlimat
merlimat deleted the mmerli/ml-terminate-fail-inflight-adds branch September 22, 2026 18:21
@Technoboy- Technoboy- assigned merlimat Sep 23, 2026
@lhotari

lhotari commented Sep 23, 2026

Copy link
Copy Markdown
Member

for cherry-picking, #25240 is required before this one

All reactions

Sorry, something went wrong.

Uh oh!

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

lhotari pushed a commit that referenced this pull request Sep 23, 2026
@merlimat @lhotari
[fix][ml] Fail in-flight adds when a managed ledger is terminated (#2…
9ec3863
…6678)

(cherry picked from commit a521e68)
@lhotari lhotari added the cherry-picked/branch-4.2 label Sep 23, 2026
lhotari pushed a commit that referenced this pull request Sep 23, 2026
@merlimat @lhotari
[fix][ml] Fail in-flight adds when a managed ledger is terminated (#2…
f65733c
…6678)

(cherry picked from commit a521e68)
@lhotari lhotari added the cherry-picked/branch-4.0 label Sep 23, 2026
This was referenced Sep 26, 2026
[fix][ml] Prevent terminated managed ledger from transitioning back to writable state #25795
Closed
[Bug][ML] ManagedLedger.terminate() can race with ledger rollover and make a terminated ledger writable again #25858
Closed
@nodece nodece mentioned this pull request Sep 28, 2026
[fix] Verify backports with CI ascentstream/pulsar#104
Closed
3 of 4 tasks
Radiancebobo pushed a commit to Radiancebobo/pulsar that referenced this pull request Oct 8, 2026
@merlimat hechengbo
[fix][ml] Fail in-flight adds when a managed ledger is terminated (ap…
cf48654
…ache#26678)
@nodece nodece mentioned this pull request Nov 5, 2026
[fix][ml][broker][client] Sync branch-as-4.0 with apache branch-4.0 (2026-09 to 2026-11, 159 commits) ascentstream/pulsar#109
Merged
4 of 5 tasks
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Nov 16, 2026
@merlimat @nodece
[fix][ml] Fail in-flight adds when a managed ledger is terminated (ap…
1231b14
…ache#26678)

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

Reviewers

@lhotari lhotari lhotari approved these changes
@nodece nodece nodece approved these changes
@dao-jun dao-jun dao-jun approved these changes

Uh oh!

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

Assignees

@merlimat merlimat

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 release/4.0.14 release/4.2.5

Projects

None yet

Milestone

5.0.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

@merlimat @lhotari @nodece @dao-jun
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.