Skip to content

Commit

Permalink
Flush logs before exiting
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Oct 20, 2023
1 parent 9b4c3fc commit 04b0187
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
16 changes: 8 additions & 8 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand All @@ -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));
}
}

Expand All @@ -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));
}
}

Expand Down Expand Up @@ -1853,7 +1853,7 @@ process.on('SIGTERM', () => {
}
isClosing = true;
closeQueues(() => {
process.exit();
logger.flush(() => process.exit());
});
});

Expand All @@ -1864,7 +1864,7 @@ process.on('SIGINT', () => {
}
isClosing = true;
closeQueues(() => {
process.exit();
logger.flush(() => process.exit());
});
});

Expand All @@ -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));
}
}

Expand All @@ -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));
}
}

Expand Down Expand Up @@ -2126,5 +2126,5 @@ startApplication()
})
.catch(err => {
logger.fatal({ msg: 'Failed to start application', err });
process.exit(1);
logger.flush(() => process.exit(1));
});
2 changes: 1 addition & 1 deletion workers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7861,5 +7861,5 @@ init()
})
.catch(err => {
logger.error({ msg: 'Failed to initialize API', err });
setImmediate(() => process.exit(3));
logger.flush(() => process.exit(3));
});
2 changes: 1 addition & 1 deletion workers/imap-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
10 changes: 4 additions & 6 deletions workers/imap.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ class ConnectionHandler {
}
});

process.exit(0);
logger.flush(() => process.exit());
}

// some general message
Expand Down Expand Up @@ -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));
});
2 changes: 1 addition & 1 deletion workers/smtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,5 +518,5 @@ init()
})
.catch(err => {
logger.error({ msg: 'Failed to initialize SMTP', err });
setImmediate(() => process.exit(3));
logger.flush(() => process.exit(3));
});

0 comments on commit 04b0187

Please sign in to comment.