[fix][broker] Avoid blocking the dispatcher close path on delayed-delivery tracker close - #26053
Merged
lhotari merged 1 commit intoJun 18, 2026
Conversation
…ivery tracker close BucketDelayedDeliveryTracker.close() blocks up to AsyncOperationTimeoutSeconds (60s) on FutureUtil.waitForAll(snapshotCreateFutures).get(...), behind the void close() of DelayedDeliveryTracker. It is invoked by PersistentDispatcherMultipleConsumers.close() (and the Classic variant) via delayedDeliveryTracker.ifPresent(DelayedDeliveryTracker::close), which runs in the topic/subscription close chain on a metadata/CompletableFuture-callback thread (e.g. the ExtensibleLoadManager getAssignedBrokerLookupData(...) .thenAccept(...) continuation during unload). A pending snapshot generation could therefore stall that callback thread for up to 60s. Add CompletableFuture<Void> closeAsync() to the DelayedDeliveryTracker interface (a default that delegates to close(), so InMemoryDelayedDeliveryTracker and DISABLE keep working). BucketDelayedDeliveryTracker overrides closeAsync() to run the cleanup under its monitor and return waitForAll(snapshotCreateFutures) (with .exceptionally to log, as before) instead of blocking on get(60s); its AutoCloseable close() now delegates to closeAsync().join() for synchronous callers. Both PersistentDispatcherMultipleConsumers and its Classic variant chain closeAsync() into the returned close future, so the tracker still finishes closing before consumers are disconnected, without blocking the callback thread.
lhotari
approved these changes
Jun 18, 2026
sandeep-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Jul 31, 2026
…ivery tracker close (apache#26053) (cherry picked from commit 82074aa)
nodece
pushed a commit
to ascentstream/pulsar
that referenced
this pull request
Aug 28, 2026
…ivery tracker close (apache#26053) (cherry picked from commit 82074aa)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
BucketDelayedDeliveryTracker.close()blocks up toAsyncOperationTimeoutSeconds(60s) onFutureUtil.waitForAll(snapshotCreateFutures).get(...), hidden behind thevoid close()ofDelayedDeliveryTracker. It is invoked byPersistentDispatcherMultipleConsumers.close()(and the Classic variant) viadelayedDeliveryTracker.ifPresent(DelayedDeliveryTracker::close), which runs inside the topic/subscription close chain on a metadata /CompletableFuture-callback thread (e.g. theExtensibleLoadManagergetAssignedBrokerLookupData(...).thenAccept(...)continuation during unload). A pending snapshot generation could therefore stall that callback thread for up to 60s.Modifications
CompletableFuture<Void> closeAsync()to theDelayedDeliveryTrackerinterface as adefaultthat delegates toclose(). Because the interface extendsAutoCloseable,close()must stayvoid; the default keepsInMemoryDelayedDeliveryTrackerand theDISABLEno-op working unchanged.BucketDelayedDeliveryTrackeroverridescloseAsync()to perform the cleanup (super.close()+ the bucket queue closes) under its monitor and then returnwaitForAll(snapshotCreateFutures)(with.exceptionally(...)logging, as before) instead of blocking onget(60s). ItsAutoCloseableclose()now delegates tocloseAsync().join()for synchronous callers (try-with-resources, tests).PersistentDispatcherMultipleConsumersand its Classic variant chaincloseAsync()into the returned close future, so the tracker still finishes closing before consumers are disconnected — but without blocking the callback thread.Verifying this change
This change is covered by existing tests, which pass:
BucketDelayedDeliveryTrackerTest,BucketDelayedDeliveryTrackerThreadSafetyTest,InMemoryDeliveryTrackerTest, andDelayedDeliveryTrackerFactoryTest.Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes