diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/ExecutionController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/ExecutionController.java index f83d6d8db44..6188aeb0eb0 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/ExecutionController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/ExecutionController.java @@ -1278,15 +1278,12 @@ public Flux> follow( cancel.set(receive); }, FluxSink.OverflowStrategy.BUFFER) - .doOnCancel(() -> { - if (cancel.get() != null) { - cancel.get().run(); - } - }) - .doOnComplete(() -> { - if (cancel.get() != null) { - cancel.get().run(); - } + .doFinally(ignored -> { + Schedulers.boundedElastic().schedule(() -> { + if (cancel.get() != null) { + cancel.get().run(); + } + }); }); } diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/LogController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/LogController.java index 027318c06f9..b0d830a4081 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/LogController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/LogController.java @@ -24,6 +24,7 @@ import org.slf4j.event.Level; import reactor.core.publisher.Flux; import reactor.core.publisher.FluxSink; +import reactor.core.scheduler.Schedulers; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -152,15 +153,12 @@ public Flux> follow( cancel.set(receive); }, FluxSink.OverflowStrategy.BUFFER) - .doOnCancel(() -> { - if (cancel.get() != null) { - cancel.get().run(); - } - }) - .doOnComplete(() -> { - if (cancel.get() != null) { - cancel.get().run(); - } + .doFinally(ignored -> { + Schedulers.boundedElastic().schedule(() -> { + if (cancel.get() != null) { + cancel.get().run(); + } + }); }); }