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] Complete a cursor delete that finds the cursor already being deleted by merlimat · Pull Request #27563 · apache/pulsar

Conversation

@merlimat

@merlimat merlimat commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Problem

ManagedLedgerImpl.asyncDeleteCursor never completes the callback of a delete that finds the cursor already being deleted (since #24569):

ManagedCursorImpl.State beforeChangingState = cursor.changeStateToDeletingIfNotDeleted();
if (beforeChangingState.isDeletingOrDeleted()) {
    log.warn().attr("cursorName", consumerName).log("Cursor is already being deleted or has been deleted");
    return;
}

A cursor stays in the managed ledger's list until the removal of its metadata completes, so another delete of the same cursor in the meantime takes this branch:

  • Two deletes of the same subscription that overlap: the second REST request never gets a response, and the admin client gives up after its request timeout (60 s by default).
  • A delete of the managed ledger (asyncDelete, which deletes its cursors) that overlaps a subscription delete never completes either.

Since #27551, the functions workers hit this on every delete of a function with instances on two workers. Every worker that ran instances of a deleted function deletes its subscriptions, and two of them do it at the same moment: the leader when it applies the delete of the function's last instance, and the other worker when it reads that delete. The other worker's assignment tailer then waits 60 s in deleteSubscription, holding the FunctionRuntimeManager lock, so it doesn't start the next function's instances. Since #27551 merged, the functions integration tests retry in every Pulsar CI run, in "CI - System - Pulsar Connectors - Thread" and "- Process" (e.g. runs 42851322491, 42871455210). The test after one that deletes a function with parallelism 2 fails its first attempt in getFunctionStatsEmpty:

org.awaitility.core.ConditionTimeoutException: Assertion condition defined as a Lambda expression in
org.apache.pulsar.tests.integration.functions.PulsarFunctionsTest expected [1] but found [0] within 10 seconds.

(or null within 10 seconds when the stats request itself waits for the lock).

Example

A local run of PulsarFunctionsJavaThreadTest with #27551. Worker 1 reads the delete of the function's last instance right after the leader (worker 0) applies it, and the broker that owns the input topic gets both subscription deletes 3 ms apart:

19:55:27,223 worker-1 FunctionRuntimeManager: Received assignment delete {key=public/default/test-exclamation-fn-nskvzrmu:1}
19:55:27,235 broker-1 [pulsar-web-56-16] PersistentSubscription: Unsubscribing                     (from the leader)
19:55:27,238 broker-1 [pulsar-web-56-9]  PersistentSubscription: Unsubscribing                     (from worker 1)
19:55:27,238 broker-1 [pulsar-web-56-9]  ManagedLedgerImpl: Cursor is already being deleted or has been deleted
19:55:27,245 broker-1 JettyRequestLogFactory: HTTP request {durationMs=15, method=DELETE, status=204, ...}   (the leader's; worker 1's never completes)
19:56:27,232 worker-1 BaseResource: Failed to perform http delete request {exception=...LowOverheadTimeoutException: Request timeout, ...}
19:56:27,248 worker-1 Actions: Error completing action {action=Cleaning up subscriptions for function ..., attempt=1, errorMsg=java.util.concurrent.TimeoutException}
19:56:28,259 worker-1 Actions: Successfully completed action {...}                                 (its retry gets 404)

Locally, each test that follows the delete of a function with parallelism 2 then takes ~62 s instead of ~2 s. In CI, the next test waits only 10 s for its function's instance, so it fails.

Change

A delete that finds the cursor being deleted now completes with the delete in progress, the way an open of a cursor that is being opened completes with that open (uninitializedCursors). The deletes in progress are tracked by cursor name in deletingCursors. A delete adds its entry when it starts and removes it once the removal of the cursor's metadata completes, after it removes the cursor from the list:

if (beforeChangingState.isDeletingOrDeleted()) {
    // A cursor stays listed until its delete in progress completes, such as the delete of a subscription that
    // two clients unsubscribe at the same time: complete with that delete
    log.debug().attr("cursorName", consumerName).log("Cursor is already being deleted");
    deletingCursors.get(consumerName).whenComplete((__, ex) -> {
        if (ex == null) {
            callback.deleteCursorComplete(ctx);
        } else {
            callback.deleteCursorFailed(ManagedLedgerException
                    .getManagedLedgerException(FutureUtil.unwrapCompletionException(ex)), ctx);
        }
    });
    return;
}
CompletableFuture<Void> deleteFuture = new CompletableFuture<>();
deletingCursors.put(consumerName, deleteFuture);
// once the metadata removal completes: remove the cursor from the list, then the entry
// (deletingCursors.remove(consumerName, deleteFuture)), and complete the callback and deleteFuture

Only asyncDeleteCursor puts a listed cursor in the Deleting state (its ledger's deletion sets Deleting and Deleted too, but only once the cursor is off the list), so a listed cursor in that state always has a delete in progress. If that delete fails, the overlapping deletes fail with the same error, and the cursor can be deleted again, as before (DeletingFailed). Both of the workers' subscription deletes now get a 204. The workers still delete the subscriptions on every worker that ran instances of the function, as #27551 intends.

Testing

  • New ManagedLedgerTest.testConcurrentDeleteCursor and testConcurrentDeleteCursorFailure: the first delete's metadata removal is held until the second delete has started. Both fail without the change, where the second delete never completes, and pass with it. ManagedLedgerTest and ManagedCursorTest pass. In one full run, testExpiredLedgerDeletionAfterManagedLedgerRestart failed: it is a rollover-timing test that doesn't delete cursors, and it passes when run alone.
  • 7 Java tests of PulsarFunctionsJavaThreadTest (in CI's order), locally, on the test image with only the changed classes replaced:
Image Per-test time Worker requests timed out (60 s)
Before #27551 1.4–3.4 s 0
With #27551 62 s for 3 tests and 31 s for one; the others 1.6–3.2 s 3
With #27551 and this change 1.4–3.0 s 0

With this change, the leader's and the other worker's overlapping deletes of the first function's subscription both returned 204 within 14 ms.

Sorry, something went wrong.

Uh oh!

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

All reactions
merlimat added 2 commits November 10, 2026 12:10
@merlimat
[fix][ml] Complete a cursor delete that finds the cursor already bein…
0e06c1f
…g deleted

ManagedLedgerImpl.asyncDeleteCursor returned without completing its callback
when the cursor was already being deleted (since apache#24569). A second delete of a
subscription that overlaps the first, such as two admin calls deleting the same
subscription, never completed: the REST request hung until the client's
request timeout (60 s for the admin client). A managed ledger delete that
overlaps a subscription delete hung the same way.

Since apache#27551, every functions worker that ran instances of a deleted function
deletes its subscriptions, and two workers do it at the same moment: the
leader when it applies the delete of the last instance, and another worker
when it reads that delete. The second worker's assignment tailer then waited
60 s in the admin call, holding the FunctionRuntimeManager lock, so the next
function's instances were not started in time and the functions integration
tests retried in every CI run.

A delete that finds the cursor being deleted now completes with the delete in
progress: it succeeds or fails with it. The deletes in progress are tracked by
cursor name, the way asyncOpenCursor tracks the opens in progress.
@merlimat
Merge remote-tracking branch 'apache/master' into mmerli/ml-concurren…
0f2cae0
…t-cursor-delete
codelipenghui
codelipenghui approved these changes Nov 10, 2026
View reviewed changes
@merlimat
merlimat merged commit b0fac7b into apache:master Nov 10, 2026
44 checks passed

Uh oh!

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

@merlimat
merlimat deleted the mmerli/ml-concurrent-cursor-delete branch November 10, 2026 21:29
lhotari pushed a commit that referenced this pull request Nov 11, 2026
@merlimat @lhotari
[fix][ml] Complete a cursor delete that finds the cursor already bein…
632d2b8
…g deleted (#27563)

(cherry picked from commit b0fac7b)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Nov 11, 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
@merlimat @lhotari
[fix][ml] Complete a cursor delete that finds the cursor already bein…
571062c
…g deleted (apache#27563)

(cherry picked from commit b0fac7b)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][ml] Complete a cursor delete that finds the cursor already bein…
3d65400
…g deleted (apache#27563)

(cherry picked from commit b0fac7b)
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

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

@merlimat @codelipenghui @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.