Skip to content

Ignore wrapped CancellationException after fromFuture cancel - #4425

Open
akashchamp wants to merge 1 commit into
reactor:mainfrom
akashchamp:4415-ignoreWrappedCancellation
Open

akashchamp wants to merge 1 commit into
reactor:mainfrom
akashchamp:4415-ignoreWrappedCancellation

Conversation

@akashchamp

Copy link
Copy Markdown

Cancelling a Mono.fromFuture(...) no longer logs an Operator called default onErrorDropped error when the future then fails with a CompletionException that wraps a CancellationException. That happens with a dependent stage of a cancelled CompletableFuture, or with HttpClient.sendAsync.

MonoCompletionStageSubscription already ignored a plain CancellationException after cancellation. It now unwraps a CompletionException before that check. Any other late failure, wrapped or not, still goes to onErrorDropped as before.

I added the two reproducers from the issue as tests in MonoCompletionStageTest, plus one checking that a wrapped non-cancellation error is still dropped. Without the fix, the two new cancellation tests fail with the dropped CompletionException: CancellationException. With it, MonoCompletionStageTest, the reactor.core.publisher.Mono* tests (1201 run, 0 failed) and spotlessCheck pass. I also ran the issue's snippet against the built classes on JDK 8: before the fix it printed two DROPPED lines, and after the fix it prints none for the cancellations.

I targeted main because the issue has no milestone and 3.8.8 is the only open one. Happy to retarget if this should go to a maintenance branch.

Fixes #4415.

When the Mono is cancelled, MonoCompletionStage ignores a late
CancellationException from the future but sends any other error to
onErrorDropped. A cancelled future can also fail with a
CompletionException wrapping the CancellationException, for instance
a dependent stage of a cancelled CompletableFuture, or the future
returned by java.net.http.HttpClient.sendAsync. That case was logged
as a dropped error even though the Mono requested the cancellation.

Unwrap a CompletionException before checking for cancellation, so it
is ignored the same way.

Fixes reactor#4415.

Signed-off-by: Akash Kumar <116457960+akashchamp@users.noreply.github.com>
@akashchamp
akashchamp requested a review from a team as a code owner October 7, 2026 18:18

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mono.fromFuture cancellation should ignore a wrapped CancellationException

1 participant