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][broker] Preserve non-durable cursor ownership during cleanup by FlorentinDUBOIS · Pull Request #26925 · apache/pulsar

Conversation

@FlorentinDUBOIS

@FlorentinDUBOIS FlorentinDUBOIS commented Oct 15, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Main Issue: #26924

Motivation

Non-durable removeConsumer currently removes a subscription from the topic map before a later executor continuation deletes its named cursor. During that gap a replacement subscription can obtain the cached cursor. The old cleanup then resolves and deletes by name, without proving that the topic still owns the original subscription instance.

The source ordering is visible at PersistentSubscription.removeConsumer, PersistentTopic.getNonDurableSubscription, and ManagedLedgerImpl cursor caching/deletion. This is a source-level race analysis; the contract regressions below exercise narrower retirement guarantees. The suspected lifecycle race has not yet been reproduced at runtime.

Modifications

  • Keep the retiring non-durable subscription reserved until its cursor-deletion callback completes, using the ledger's existing creation lock and exact-instance map removal.
  • Add a monitor-guarded terminal retirement state so a waiting consumer or a later reset cannot reopen the old subscription after a reset callback clears its ordinary fence.
  • Serialize reset admission, fence CAS and publication of the in-progress reset future under the subscription monitor. A reset already admitted is allowed to finish before asynchronous retirement; no future is waited on under that monitor. Reset retirement preserves its cursor rather than deleting it.
  • Reuse asyncDeleteCursor, FutureUtil.supplySafely and the existing executor. Deletion callbacks only complete a future; map/statistics continuation runs via thenComposeAsync, outside the ledger callback's lock.
  • Preserve existing name-only removal callers, durable cleanup behavior, and closeCursor/resumeAfterFence fence operations. No dependencies, wire format or configuration changes.

Recovery limitation: an unexpected deletion error keeps the old subscription terminally fenced and reserved; no automatic recovery is added. Missing-cursor/missing-ledger completions are treated as already deleted. This behavior needs review and native failure-path tests.

Verifying this change

  • Add two native contract regressions observed failing on the unpatched production code and passing after restoring the proposal, with identical tests and commands.
  • Run the full PersistentSubscriptionTest class: 6 tests passed, no failures or skips.
  • Run ./gradlew quickCheck and ./gradlew sanityCheck: both passed locally with Temurin JDK 25.0.4.1+1.
  • Reproduce the complete real-ledger cursor-reuse/deferred-deletion interleaving at runtime.
  • Verify the remaining reset failure paths, conditional replacement and recovery after unexpected cursor-deletion errors.

The two tests cover distinct contracts through the existing Java fixture:

  1. A consumer queued behind an admitted reset, and a new consumer after that reset, cannot reopen the retired subscription instance.
  2. The topic retains the old subscription reservation until the captured cursor-deletion callback completes, then removes it. The ledger is mocked in this contract test; it does not reproduce actual cursor-cache reuse or physical cursor deletion.

Both tests failed at their contract assertions with the two production files restored to parent commit c1aaf961086380fbdd7bae734e2fed47e54f7e2a (2 tests, 2 failures, no skips). After restoring production commit 8e23ec454fe74ce2b416f6778505d8b90d1a6730, the unchanged tests passed (2 tests, no failures or skips). Both executions forced the test task to run, disabled the build cache and retries, and collected all failures:

./gradlew :pulsar-broker:test --rerun --no-build-cache \
  --tests 'org.apache.pulsar.broker.service.persistent.PersistentSubscriptionTest.testNonDurableSubscription*' \
  -PtestRetryCount=0 -PtestFailFast=false
./gradlew :pulsar-broker:test --rerun --no-build-cache \
  --tests 'org.apache.pulsar.broker.service.persistent.PersistentSubscriptionTest' \
  -PtestRetryCount=0 -PtestFailFast=false
./gradlew quickCheck
./gradlew sanityCheck

The normal pre-push hook also ran ./gradlew test successfully before publishing test commit ef7f48c34855d3293ca1f7f4037fd27922877c99.

The prior fork Pulsar CI and Flaky suite passed for production commit 8e23ec454fe74ce2b416f6778505d8b90d1a6730; those runs predate the new tests. CI for the added tests must be evaluated separately. The complete suspected lifecycle race has not yet been reproduced at runtime, and no client reconnect timeout is attributed to it by these contract tests. Recovery after an unexpected cursor-deletion failure remains an open limitation. These results do not establish merge readiness.

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

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model — changes asynchronous retirement ordering and serializes reset admission; no new executor or blocking future wait.
  • 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
@FlorentinDUBOIS
fix(broker): retain non-durable cursor ownership during cleanup
8e23ec4
Keep retired subscriptions reserved until cursor deletion completes,
then remove only the expected subscription instance. This prevents an
old name-based cleanup from deleting a cursor handed to a replacement.

Serialize reset admission with terminal retirement and let an admitted
reset finish asynchronously before cleanup. Reject consumers waiting
on the retired subscription without reopening it through a reset fence.

Refs: apache#26924
Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS FlorentinDUBOIS mentioned this pull request Oct 15, 2026
Preserve non-durable cursor ownership during deferred cleanup #26924
Open
@FlorentinDUBOIS
FlorentinDUBOIS marked this pull request as ready for review October 15, 2026 12:16
@FlorentinDUBOIS

FlorentinDUBOIS commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

@lhotari I haven't been able to add and validate a dedicated regression test for this race because Codex and Claude have flagged and blocked those attempts through their security checks. The existing fork CI passes, but that does not replace a deterministic reproducer and a regression test that fails without the fix and passes with it.

All reactions

Sorry, something went wrong.

Uh oh!

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

@FlorentinDUBOIS
test(broker): cover non-durable subscription retirement contracts
ef7f48c
Verify that consumers queued behind a reset cannot revive a retired
subscription, and that cursor deletion retains the subscription
reservation until its completion callback.

Exercise both contracts through the existing subscription fixture.

Refs: apache#26924
Signed-off-by: Florentin Dubois <[email protected]>
codelipenghui
codelipenghui reviewed Oct 15, 2026
View reviewed changes
Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java Resolved

Uh oh!

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

FlorentinDUBOIS and others added 2 commits October 19, 2026 09:26
@FlorentinDUBOIS
fix(broker): reject durable admission during non-durable retirement
5df25f5
Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
Merge branch 'master' into fix/non-durable-subscription-cleanup
daf4104
codelipenghui
codelipenghui approved these changes Oct 20, 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 daf4104991dbd746d34aa7a58e0ee58000977f20. The previous mixed-durability ownership finding is resolved: durable admission checks the reservation under the ledger lock before opening a cursor.

Focused local validation passed the new real-ledger regression and both retirement-contract tests: 3 tests, no failures or skips. No actionable findings identified within the reviewed scope.

The unpatched baseline and complete original reconnect interleaving were not independently reproduced.

Sorry, something went wrong.

Uh oh!

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

All reactions
lhotari
lhotari approved these changes Oct 20, 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 working on this fix. I traced the original interleaving and the retirement now closes it: the old subscription stays in the topic map until asyncDeleteCursor has finished (under the ledger monitor that getNonDurableSubscription and asyncOpenCursor also use), so a same-name request in that window finds the retiring subscription and is rejected with a retriable SubscriptionFencedException instead of picking up the cached cursor, and the map entry is then removed by exact instance. The non-durable delete in ManagedLedgerImpl.asyncDeleteCursor completes synchronously and removes the cursor from cursors and activeCursors, addConsumerInternal checks the terminal flag before cursor.setActive(), so I could not find a path that leaks a cursor or re-activates a deleted one. The old blocking deleteCursor call on the executor is also gone. I ran the three new tests on this head and they pass; reverting the PersistentSubscription change makes all three fail, and neutralising the durable-admission guard makes the real-ledger test fail on the orphan-cursor assertion. Two small, non-blocking notes are inline.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java Resolved

Uh oh!

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

Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java Resolved

Uh oh!

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

Comment thread ...broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentSubscription.java Resolved

Uh oh!

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

@FlorentinDUBOIS
fix(broker): cover non-durable subscription cleanup failures
357cfef
Signed-off-by: Florentin Dubois <[email protected]>
lhotari
lhotari approved these changes Oct 20, 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. The follow-up commit addresses all three earlier comments: the warning text is corrected, the exact-instance removal is now pinned by a test, and the unexpected delete-failure contract is documented and covered for both the asynchronous and synchronous failure paths.

Sorry, something went wrong.

Uh oh!

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

All reactions
@lhotari
lhotari merged commit c9b020b into apache:master Oct 20, 2026
81 of 83 checks passed

Uh oh!

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

lhotari pushed a commit that referenced this pull request Oct 20, 2026
@FlorentinDUBOIS @lhotari
[fix][broker] Preserve non-durable cursor ownership during cleanup (#…
e610426
…26925)

Signed-off-by: Florentin Dubois <[email protected]>
(cherry picked from commit c9b020b)
@lhotari lhotari added release/5.0.1 cherry-picked/branch-5.0 labels Oct 20, 2026
This was referenced Oct 28, 2026
[fix][broker] Prevent mixed-durability subscription creation races Denovo1998/pulsar#56
Open
[fix][broker] Prevent mixed-durability subscription creation races #27214
Merged
@kaminski-dev kaminski-dev mentioned this pull request Nov 5, 2026
[Bug][broker] Topic policy updates and topic deletion wait forever when the __change_events reader stops, and a failed policy cache init leaks the reader #27366
Closed
3 tasks done
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
@FlorentinDUBOIS @lhotari
[fix][broker] Preserve non-durable cursor ownership during cleanup (a…
6cc7dc7
…pache#26925)

Signed-off-by: Florentin Dubois <[email protected]>
(cherry picked from commit c9b020b)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@FlorentinDUBOIS @lhotari
[fix][broker] Preserve non-durable cursor ownership during cleanup (a…
c067c18
…pache#26925)

Signed-off-by: Florentin Dubois <[email protected]>
(cherry picked from commit c9b020b)
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
@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.1

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

3 participants

@FlorentinDUBOIS @lhotari @codelipenghui
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.