File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
platform-service-framework/src/main/java/org/hypertrace/core/serviceframework Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -133,12 +133,12 @@ public void start() {
133133 context .addServlet (new ServletHolder (new JVMDiagnosticServlet ()), "/diags/*" );
134134
135135 final Thread thread = new Thread (this ::doStart );
136+ thread .setUncaughtExceptionHandler (
137+ (threadWithException , exception ) -> this .shutdownWithError (exception ));
136138 try {
137139 thread .start ();
138140 } catch (Exception e ) {
139- LOGGER .error ("Failed to start thread for application." , e );
140- System .exit (1 );
141- throw e ;
141+ this .shutdownWithError (e );
142142 }
143143
144144 // Start the webserver.
@@ -152,9 +152,7 @@ public void start() {
152152 thread .join ();
153153 adminServer .join ();
154154 } catch (Exception e ) {
155- LOGGER .error ("Failed to start service servlet." );
156- this .shutdown ();
157- System .exit (1 );
155+ this .shutdownWithError (e );
158156 }
159157 }
160158
@@ -190,4 +188,14 @@ public void shutdown() {
190188 PlatformMetricsRegistry .stop ();
191189 LOGGER .info ("Service - {} is shutdown." , getServiceName ());
192190 }
191+
192+ private void shutdownWithError (Throwable exception ) {
193+ LOGGER .error ("Shutting down due to unrecoverable exception" , exception );
194+ try {
195+ this .shutdown ();
196+ } catch (Exception e ) {
197+ // Ignore if failed to shut down
198+ }
199+ System .exit (1 );
200+ }
193201}
You can’t perform that action at this time.
0 commit comments