[fix][common] Handle synchronous failures from future suppliers#25939
Open
Radiancebobo wants to merge 5 commits into
Open
[fix][common] Handle synchronous failures from future suppliers#25939Radiancebobo wants to merge 5 commits into
Radiancebobo wants to merge 5 commits into
Conversation
Contributor
Author
|
There's a similar PR #25931 |
lhotari
reviewed
Jun 5, 2026
…reUtil.java Co-authored-by: Lari Hotari <lhotari@users.noreply.github.com>
…reUtil.java Co-authored-by: Lari Hotari <lhotari@users.noreply.github.com>
lhotari
reviewed
Jun 5, 2026
Contributor
Author
|
/pulsarbot rerun |
Contributor
Author
|
I have executed these and made sure there are no issues. ./gradlew :pulsar-common:test :managed-ledger:test --rerun-tasks -PtestRetryCount=0 \
--tests org.apache.pulsar.common.util.FutureUtilTest \
--tests org.apache.bookkeeper.mledger.util.FuturesTest
./gradlew :pulsar-common:spotlessCheck :pulsar-common:checkstyleMain :pulsar-common:checkstyleTest
|
lhotari
reviewed
Jun 5, 2026
lhotari
reviewed
Jun 5, 2026
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
Some asynchronous helper methods accept a
Supplier<CompletableFuture<T>>and assume the supplier always returns a future. However, a supplier can also fail synchronously before creating the future.Before this change, those synchronous failures could bypass the expected asynchronous error handling path:
FutureUtil.Sequencer.sequentialcould throw directly instead of returning a failed future.FutureUtil.composeAsynccould throw inside the executor task and leave the returned future incomplete.Futures.executeWithRetryin managed-ledger could throw before entering the retry state machine, so a retryable transient failure from the operation setup path would not be retried.These helpers should preserve the
CompletableFuturecontract: callers should receive a completed or exceptionally completed future, rather than having synchronous exceptions escape or leave the returned future hanging.Modifications
This change updates the future supplier handling paths to convert synchronous supplier failures into failed futures:
FutureUtilto safely invokeSupplier<CompletableFuture<T>>.FutureUtil.Sequencer.sequentialto use the safe supplier invocation path.FutureUtil.composeAsyncto complete the returned future exceptionally when the supplier fails synchronously.Futures.executeWithRetryto route synchronous supplier failures through the existing retry logic.nullcomplete exceptionally withNullPointerExceptioninstead of causing an unchecked synchronous failure.Verifying this change
This change added tests and can be verified as follows:
FutureUtilTest.testSequencerReturnsFailedFutureWhenTaskThrowsSynchronouslyFutureUtilTest.testComposeAsyncReturnsFailedFutureWhenSupplierThrowsSynchronouslyFuturesTest.testExecuteWithRetryHandlesSynchronousFailureLocal verification:
./gradlew :pulsar-common:test --tests org.apache.pulsar.common.util.FutureUtilTest -PtestRetryCount=0 --rerun-tasks./gradlew :managed-ledger:test --tests org.apache.bookkeeper.mledger.util.FuturesTest -PtestRetryCount=0 --rerun-tasksDoes this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes