Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track configuration initialization state for using loggers #44619

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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