@@ -118,7 +118,7 @@ public void start(String[] args) {
118118 ProcessState .getInstance (this ).addState (ProcessState .PROCESS_STATE .SHUTTING_DOWN , null );
119119 stopApp ();
120120
121- Logging .info (this , "Goodbye" );
121+ Logging .info (this , "Goodbye" , true );
122122 } catch (Exception e ) {
123123
124124 ProcessState .getInstance (this ).addState (ProcessState .PROCESS_STATE .SHUTTING_DOWN , null );
@@ -143,14 +143,16 @@ private void init() throws IOException {
143143 // Handle kill signal gracefully
144144 handleKillSignalForWhenItHappens ();
145145
146- // loading storage layer
147- StorageLayer . init (this , CLIOptions . get ( this ). getInstallationPath () + "plugin/" ,
146+ // loading configs for core.
147+ Config . loadConfig (this ,
148148 CLIOptions .get (this ).getConfigFilePath () == null
149149 ? CLIOptions .get (this ).getInstallationPath () + "config.yaml"
150150 : CLIOptions .get (this ).getConfigFilePath ());
151151
152- // loading configs for core.
153- Config .loadConfig (this ,
152+ Logging .info (this , "Completed config.yaml loading." , true );
153+
154+ // loading storage layer
155+ StorageLayer .init (this , CLIOptions .get (this ).getInstallationPath () + "plugin/" ,
154156 CLIOptions .get (this ).getConfigFilePath () == null
155157 ? CLIOptions .get (this ).getInstallationPath () + "config.yaml"
156158 : CLIOptions .get (this ).getConfigFilePath ());
@@ -161,8 +163,6 @@ private void init() throws IOException {
161163 // init file logging
162164 Logging .initFileLogging (this );
163165
164- Logging .info (this , "Completed config.yaml loading." );
165-
166166 // initialise cron job handler
167167 Cronjobs .init (this );
168168
@@ -217,7 +217,7 @@ private void init() throws IOException {
217217 // NOTE: If the message below is changed, make sure to also change the corresponding check in the CLI program
218218 // for start command
219219 Logging .info (this , "Started SuperTokens on " + Config .getConfig (this ).getHost (this ) + ":"
220- + Config .getConfig (this ).getPort (this ) + " with PID: " + ProcessHandle .current ().pid ());
220+ + Config .getConfig (this ).getPort (this ) + " with PID: " + ProcessHandle .current ().pid (), true );
221221 }
222222
223223 @ TestOnly
@@ -314,8 +314,24 @@ public void killForTestingAndWaitForShutdown() throws InterruptedException {
314314 // must not throw any error
315315 // must wait for everything to finish and only then exit
316316 private void stopApp () {
317- Logging .info (this , "Stopping SuperTokens..." );
318317 try {
318+ // We do this first because it was initialized first.
319+ // so if something else fails below due to config not initialized,
320+ // then at least this will be cleared.
321+ if (this .shutdownHook != null ) {
322+ try {
323+ Runtime .getRuntime ().removeShutdownHook (this .shutdownHook );
324+ } catch (IllegalStateException e ) {
325+ // we are shutting down already.. so doesn't matter
326+ }
327+ }
328+
329+ // Note that logging may throw an error if the config
330+ // was not loaded due to an error in config. But this is OK
331+ // since we load config before loading anything else
332+ // below this, and this whole block is surrounded in a
333+ // try / catch.
334+ Logging .info (this , "Stopping SuperTokens..." , true );
319335 Webserver .getInstance (this ).stop ();
320336 Cronjobs .shutdownAndAwaitTermination (this );
321337 if (!Main .isTesting ) {
@@ -340,19 +356,12 @@ private void stopApp() {
340356 */
341357 }
342358 }
343- if (this .shutdownHook != null ) {
344- try {
345- Runtime .getRuntime ().removeShutdownHook (this .shutdownHook );
346- } catch (IllegalStateException e ) {
347- // we are shutting down already.. so doesn't matter
348- }
349- }
350359 removeDotStartedFileForThisProcess ();
351360 Logging .stopLogging (this );
352361 // uncomment this when you want to confirm that processes are actually shut.
353362 // printRunningThreadNames();
354363
355- } catch (Exception ignored ) {
364+ } catch (Throwable ignored ) {
356365
357366 }
358367 }
0 commit comments