Skip to content
Merged
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 @@ -133,12 +133,12 @@ public void start() {
context.addServlet(new ServletHolder(new JVMDiagnosticServlet()), "/diags/*");

final Thread thread = new Thread(this::doStart);
thread.setUncaughtExceptionHandler(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The potential risk here is that there may be some exceptions that are ignorable today and uncaught that would lead to a server quit. IMO we should be fixing any such spots (And kube will recover for us in the interim)

(threadWithException, exception) -> this.shutdownWithError(exception));
try {
thread.start();
} catch (Exception e) {
LOGGER.error("Failed to start thread for application.", e);
System.exit(1);
throw e;
this.shutdownWithError(e);
}

// Start the webserver.
Expand All @@ -152,9 +152,7 @@ public void start() {
thread.join();
adminServer.join();
} catch (Exception e) {
LOGGER.error("Failed to start service servlet.");
this.shutdown();
System.exit(1);
this.shutdownWithError(e);
}
}

Expand Down Expand Up @@ -190,4 +188,14 @@ public void shutdown() {
PlatformMetricsRegistry.stop();
LOGGER.info("Service - {} is shutdown.", getServiceName());
}

private void shutdownWithError(Throwable exception) {
LOGGER.error("Shutting down due to unrecoverable exception", exception);
try {
this.shutdown();
} catch (Exception e) {
// Ignore if failed to shut down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially. The shutdown method calls various shutdown hooks, which each service is able to define itself. If any happen to throw (which seems like it's possible especially given it can now be called before startup), we don't want them to actually prevent the shutdown from completing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log or it would be too noisy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a noise volume concern, i was just concerned it would be misleading. Basically something has happened to cause the server to shutdown abnormally. If we hit more errors when trying to force that shutdown (from a server that may not have started in the first place), we don't want those to distract from the root cause.

}
System.exit(1);
}
}