From 607320eafb92cd11f02f8b9b7ee5302a307fb60d Mon Sep 17 00:00:00 2001 From: Julien Ponge Date: Wed, 21 Feb 2024 17:05:35 +0100 Subject: [PATCH] fix: backport fix for cancellation in Uni to Multi bridge --- .../converters/uni/UniToMultiPublisher.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/implementation/src/main/java/io/smallrye/mutiny/converters/uni/UniToMultiPublisher.java b/implementation/src/main/java/io/smallrye/mutiny/converters/uni/UniToMultiPublisher.java index 7540a0e24..7e38b55c1 100644 --- a/implementation/src/main/java/io/smallrye/mutiny/converters/uni/UniToMultiPublisher.java +++ b/implementation/src/main/java/io/smallrye/mutiny/converters/uni/UniToMultiPublisher.java @@ -58,19 +58,21 @@ public Context context() { @Override public void cancel() { - if (upstream != null) { - upstream.cancel(); + if (STATE_UPDATER.getAndSet(this, State.DONE) != State.DONE) { + if (upstream != null) { + upstream.cancel(); + } } } @Override public void request(long n) { - if (n <= 0L) { - downstream.onError(new IllegalArgumentException("Invalid request")); - return; - } if (STATE_UPDATER.compareAndSet(this, State.INIT, State.UNI_REQUESTED)) { - AbstractUni.subscribe(uni, this); + if (n <= 0L) { + onFailure(new IllegalArgumentException("Invalid request")); + } else { + AbstractUni.subscribe(uni, this); + } } }