From 1d82193adafd00717fde61118ccf539d5f23c6f0 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 10 Nov 2022 09:29:19 +0200 Subject: [PATCH 1/2] Properly wait for s2i build to complete Furthermore, Ensure that the executor used is shutdown Co-authored-by: George Gastaldi --- .../image/s2i/deployment/S2iProcessor.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iProcessor.java b/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iProcessor.java index 1b2f0fa2bb296..3052fe0666e5a 100644 --- a/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iProcessor.java +++ b/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iProcessor.java @@ -17,7 +17,8 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executor; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; @@ -372,19 +373,33 @@ private static void s2iBuild(OpenShiftClient client, BuildConfig buildConfig, Fi } private static void waitForBuildComplete(OpenShiftClient client, S2iConfig s2iConfig, String buildName, Closeable watch) { - Executor executor = Executors.newSingleThreadExecutor(); + CountDownLatch latch = new CountDownLatch(1); + ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() -> { try { client.builds().withName(buildName).waitUntilCondition(b -> !RUNNING.equalsIgnoreCase(b.getStatus().getPhase()), s2iConfig.buildTimeout.toMillis(), TimeUnit.MILLISECONDS); } finally { - try { - watch.close(); - } catch (IOException e) { - LOG.debug("Error closing log reader."); - } + latch.countDown(); } }); + try { + latch.await(); + } catch (InterruptedException e) { + LOG.debug("Error waiting for build to complete.", e); + } finally { + try { + watch.close(); + } catch (IOException e) { + LOG.debug("Error closing log reader.", e); + } + try { + executor.shutdown(); + } catch (Exception e) { + LOG.debug("Error shutting down executor", e); + } + } + } public static Predicate distinctByResourceKey() { From cdc35d4a7b7c6e284aa973b756deb02654380f1e Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 10 Nov 2022 09:30:33 +0200 Subject: [PATCH 2/2] Ensure that the executor used for hot deployment of messaging apps is shutdown --- .../devmode/ReactiveMessagingHotReplacementSetup.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/extensions/smallrye-reactive-messaging/runtime/src/main/java/io/quarkus/smallrye/reactivemessaging/runtime/devmode/ReactiveMessagingHotReplacementSetup.java b/extensions/smallrye-reactive-messaging/runtime/src/main/java/io/quarkus/smallrye/reactivemessaging/runtime/devmode/ReactiveMessagingHotReplacementSetup.java index da735642fa556..de341cfefb784 100644 --- a/extensions/smallrye-reactive-messaging/runtime/src/main/java/io/quarkus/smallrye/reactivemessaging/runtime/devmode/ReactiveMessagingHotReplacementSetup.java +++ b/extensions/smallrye-reactive-messaging/runtime/src/main/java/io/quarkus/smallrye/reactivemessaging/runtime/devmode/ReactiveMessagingHotReplacementSetup.java @@ -1,7 +1,7 @@ package io.quarkus.smallrye.reactivemessaging.runtime.devmode; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.function.Supplier; @@ -17,7 +17,7 @@ public class ReactiveMessagingHotReplacementSetup implements HotReplacementSetup private HotReplacementContext context; private volatile long nextUpdate; - private final Executor executor = Executors.newSingleThreadExecutor(); + private final ExecutorService executor = Executors.newSingleThreadExecutor(); @Override public void setupHotDeployment(HotReplacementContext context) { @@ -25,6 +25,11 @@ public void setupHotDeployment(HotReplacementContext context) { DevModeSupportConnectorFactoryInterceptor.register(new OnMessage()); } + @Override + public void close() { + executor.shutdown(); + } + private class OnMessage implements Supplier> { @Override public CompletableFuture get() {