diff --git a/server.js b/server.js index 4b580b1f..cabf7ea6 100644 --- a/server.js +++ b/server.js @@ -256,7 +256,7 @@ if (preparedSettingsString) { preparedSettings = value; } catch (err) { logger.error({ msg: 'Received invalid settings string', input: preparedSettingsString, err }); - process.exit(1); + logger.flush(() => process.exit(1)); } } @@ -270,7 +270,7 @@ if (preparedTokenString) { } } catch (err) { logger.error({ msg: 'Received invalid token string', input: preparedTokenString, err }); - process.exit(1); + logger.flush(() => process.exit(1)); } } @@ -284,7 +284,7 @@ if (preparedPasswordString) { } } catch (err) { logger.error({ msg: 'Received invalid password string', input: preparedPasswordString, err }); - process.exit(1); + logger.flush(() => process.exit(1)); } } @@ -1853,7 +1853,7 @@ process.on('SIGTERM', () => { } isClosing = true; closeQueues(() => { - process.exit(); + logger.flush(() => process.exit()); }); }); @@ -1864,7 +1864,7 @@ process.on('SIGINT', () => { } isClosing = true; closeQueues(() => { - process.exit(); + logger.flush(() => process.exit()); }); }); @@ -1888,7 +1888,7 @@ const startApplication = async () => { await setLicense(licenseData, licenseFile); } catch (err) { logger.fatal({ msg: 'Failed to verify provided license key file', source: config.licensePath, err }); - return process.exit(13); + return logger.flush(() => process.exit(13)); } } @@ -1901,7 +1901,7 @@ const startApplication = async () => { } } catch (err) { logger.fatal({ msg: 'Failed to verify provided license key data', source: 'import', err }); - return process.exit(13); + return logger.flush(() => process.exit(13)); } } @@ -2126,5 +2126,5 @@ startApplication() }) .catch(err => { logger.fatal({ msg: 'Failed to start application', err }); - process.exit(1); + logger.flush(() => process.exit(1)); }); diff --git a/workers/api.js b/workers/api.js index 9ba06dc4..37ab75a1 100644 --- a/workers/api.js +++ b/workers/api.js @@ -7861,5 +7861,5 @@ init() }) .catch(err => { logger.error({ msg: 'Failed to initialize API', err }); - setImmediate(() => process.exit(3)); + logger.flush(() => process.exit(3)); }); diff --git a/workers/imap-proxy.js b/workers/imap-proxy.js index ad5a40d7..859ea8a2 100644 --- a/workers/imap-proxy.js +++ b/workers/imap-proxy.js @@ -75,5 +75,5 @@ run() }) .catch(err => { logger.error({ msg: 'Failed to initialize IMAP server', err }); - setImmediate(() => process.exit(3)); + logger.flush(() => process.exit(3)); }); diff --git a/workers/imap.js b/workers/imap.js index efa1e8ed..ead67f5c 100644 --- a/workers/imap.js +++ b/workers/imap.js @@ -547,7 +547,7 @@ class ConnectionHandler { } }); - process.exit(0); + logger.flush(() => process.exit()); } // some general message @@ -737,20 +737,18 @@ parentPort.on('message', message => { process.on('SIGTERM', () => { connectionHandler.kill().catch(err => { logger.error({ msg: 'Execution failed', err }); - process.exit(4); + logger.flush(() => process.exit(4)); }); }); process.on('SIGINT', () => { connectionHandler.kill().catch(err => { logger.error({ msg: 'Execution failed', err }); - process.exit(5); + logger.flush(() => process.exit(5)); }); }); main().catch(err => { logger.fatal({ msg: 'Execution failed', err }); - logger.flush(() => { - process.exit(6); - }); + logger.flush(() => process.exit(6)); }); diff --git a/workers/smtp.js b/workers/smtp.js index 0c3468f1..2742f676 100644 --- a/workers/smtp.js +++ b/workers/smtp.js @@ -518,5 +518,5 @@ init() }) .catch(err => { logger.error({ msg: 'Failed to initialize SMTP', err }); - setImmediate(() => process.exit(3)); + logger.flush(() => process.exit(3)); });