diff --git a/core/deployment/src/main/java/io/quarkus/deployment/configuration/RunTimeConfigurationGenerator.java b/core/deployment/src/main/java/io/quarkus/deployment/configuration/RunTimeConfigurationGenerator.java index 75701f2430b5b..f14e9627fb45f 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/configuration/RunTimeConfigurationGenerator.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/configuration/RunTimeConfigurationGenerator.java @@ -687,7 +687,7 @@ public void run() { ResultHandle niceErrorMessage = isError .invokeStaticMethod( MethodDescriptor.ofMethod(ConfigDiagnostic.class, "getNiceErrorMessage", String.class)); - readConfig.invokeStaticMethod(CD_RESET_ERROR); + isError.invokeStaticMethod(CD_RESET_ERROR); // throw the proper exception final ResultHandle finalErrorMessageBuilder = isError.newInstance(SB_NEW); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java index 7de869ce931a0..a274fd09848cb 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java @@ -119,7 +119,6 @@ public void accept(Integer integer) { public synchronized void restartApp(Set changedResources) { restarting = true; stop(); - restarting = false; Timing.restart(curatedApplication.getAugmentClassLoader()); deploymentProblem = null; ClassLoader old = Thread.currentThread().getContextClassLoader(); @@ -134,6 +133,7 @@ public synchronized void restartApp(Set changedResources) { log.error("Failed to start quarkus", t); } } finally { + restarting = false; Thread.currentThread().setContextClassLoader(old); } } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/Application.java b/core/runtime/src/main/java/io/quarkus/runtime/Application.java index c6b2fb59bd2d7..47be7673547ab 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/Application.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/Application.java @@ -5,6 +5,7 @@ import java.util.concurrent.locks.Lock; import org.eclipse.microprofile.config.spi.ConfigProviderResolver; +import org.jboss.logging.Logger; import org.wildfly.common.Assert; import org.wildfly.common.lock.Locks; @@ -88,6 +89,12 @@ public final void start(String[] args) { doStart(args); } catch (Throwable t) { stateLock.lock(); + final ConfigProviderResolver cpr = ConfigProviderResolver.instance(); + try { + cpr.releaseConfig(cpr.getConfig()); + } catch (IllegalStateException ignored) { + // just means no config was installed, which is fine + } try { state = ST_STOPPED; stateCond.signalAll(); @@ -129,6 +136,15 @@ public final void close() { * stop, that exception is propagated. */ public final void stop() { + stop(null); + } + + /** + * Stop the application. If another thread is also trying to stop the application, this method waits for that + * thread to finish. Returns immediately if the application is already stopped. If an exception is thrown during + * stop, that exception is propagated. + */ + public final void stop(Runnable afterStopTask) { final Lock stateLock = this.stateLock; stateLock.lock(); try { @@ -171,6 +187,13 @@ public final void stop() { doStop(); } finally { currentApplication = null; + if (afterStopTask != null) { + try { + afterStopTask.run(); + } catch (Throwable t) { + Logger.getLogger(Application.class).error("Failed to run stop task", t); + } + } stateLock.lock(); try { state = ST_STOPPED; diff --git a/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java b/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java index 9827cf7e6988b..629062c9a1292 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java @@ -142,8 +142,12 @@ public static final void run(Application application, Class