Skip to content

Commit

Permalink
Track configuration initialization state for using loggers
Browse files Browse the repository at this point in the history
Closes #42084
  • Loading branch information
zakkak committed Nov 22, 2024
1 parent 296ffde commit 492fab7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.quarkus.gizmo.ClassCreator;
import io.quarkus.gizmo.ClassOutput;
import io.quarkus.gizmo.MethodCreator;
import io.quarkus.gizmo.MethodDescriptor;
import io.quarkus.runtime.StartupContext;
import io.quarkus.runtime.StartupTask;

Expand Down Expand Up @@ -41,6 +42,8 @@ void setupRuntimeConfig(
method.getMethodParam(0), method.load("RuntimeConfigSetupBuildStep.setupRuntimeConfig"));

method.invokeStaticMethod(C_CREATE_RUN_TIME_CONFIG);
method.invokeStaticMethod(MethodDescriptor.ofMethod("io.quarkus.runtime.ApplicationLifecycleManager",
"setConfigSetupCompleted", void.class, boolean.class), method.load(true));
method.returnValue(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ private ApplicationLifecycleManager() {
private static ShutdownHookThread shutdownHookThread;

private static int exitCode = -1;
// this is used to determine if the config setup has completed to determine if we can use logs or not for error
// reporting in early crashes. Its value is set by io.quarkus.deployment.steps.RuntimeConfigSetup#deploy
private static boolean configSetupCompleted;
private static volatile boolean shutdownRequested;
private static volatile Application currentApplication;
private static boolean vmShuttingDown;
Expand Down Expand Up @@ -205,8 +208,12 @@ public static void run(Application application, Class<? extends QuarkusApplicati
&& !StringUtil.isNullOrEmpty(rootCause.getMessage())) {
System.err.println(rootCause.getMessage());
} else {
applicationLogger.errorv(e, "Failed to start application");
ensureConsoleLogsDrained();
if (configSetupCompleted) {
applicationLogger.errorv(e, "Failed to start application");
ensureConsoleLogsDrained();
} else {
e.printStackTrace();
}
}
}
stateLock.lock();
Expand Down Expand Up @@ -241,6 +248,14 @@ public static void run(Application application, Class<? extends QuarkusApplicati
(exitCodeHandler == null ? defaultExitCodeHandler : exitCodeHandler).accept(getExitCode(), null); //this may not be called if shutdown was initiated by a signal
}

/**
* This method is only meant to be used by {@code io.quarkus.deployment.steps.RuntimeConfigSetup#deploy}
*/
@SuppressWarnings("unused")
public static void setConfigSetupCompleted(boolean configSetupCompleted) {
ApplicationLifecycleManager.configSetupCompleted = configSetupCompleted;
}

// this is needed only when async console logging is enabled
private static void ensureConsoleLogsDrained() {
AsyncHandler asyncHandler = null;
Expand Down

0 comments on commit 492fab7

Please sign in to comment.