fix: use exitCode to allow streams to drain on exit

This commit is contained in:
Alexis
2021-09-10 17:22:23 +09:30
parent 7ac1684f19
commit 6531d6d59e
4 changed files with 10 additions and 6 deletions
+1 -1
View File
@@ -273,7 +273,7 @@ async function main() {
if (!command) {
if (mainOptions.version) {
await commands.version();
process.exit();
process.exit(0);
}
// Run help command
+3 -2
View File
@@ -12,7 +12,8 @@ import { coreLogger } from '../../log';
export const exitApp = (error?: Error, exitCode?: number) => {
if (!error) {
// Kill application immediately
process.exit(exitCode ?? 0);
process.exitCode = exitCode ?? 0;
return;
}
// Allow non-fatal errors to throw but keep the app running
@@ -32,6 +33,6 @@ export const exitApp = (error?: Error, exitCode?: number) => {
coreLogger.error(error);
// Kill application
process.exit(exitCode);
process.exitCode = exitCode;
}
};
+1 -1
View File
@@ -23,6 +23,6 @@ export const globalErrorHandler = (error: Error) => {
console.error(error);
// Kill application
process.exit(1);
process.exitCode = 1;
}
};
+5 -2
View File
@@ -8,7 +8,7 @@ import am from 'am';
import * as Sentry from '@sentry/node';
import exitHook from 'async-exit-hook';
import getServerAddress from 'get-server-address';
import { core, states, coreLogger, log, apiManager, apiManagerLogger } from './core';
import { core, states, coreLogger, log, apiManager, apiManagerLogger, logger } from './core';
import { server } from './server';
import { mothership } from './mothership/subscribe-to-servers';
import { startInternal, sockets } from './mothership';
@@ -158,6 +158,9 @@ am(async () => {
log.error(error);
});
}, async (error: NodeJS.ErrnoException) => {
// Log error to syslog
log.error(error);
// Send error to server for debugging
Sentry.captureException(error);
@@ -172,6 +175,6 @@ am(async () => {
await Sentry.flush(5000);
// Kill application
process.exit(1);
process.exitCode = 1;
});
});