Skip to content

Commit 9e1b3e8

Browse files
committed
fix: exit the process on unhandled rejections
unhandled rejections are usually an indication of something going pretty wrong with the code, with no way to recover. so far, we've been silently ignoring those (and only logging) because we didn't know when these things would tend to happen on the Kubernetes Monitor. today we're a bit more confident about the unhandled rejections we're seeing, and we believe it's better to exit the process and let the pod restart. also removing the "promise" prints as they always end up as an empty object, and never provide any interesting data.
1 parent 8350de5 commit 9e1b3e8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ process.on('uncaughtException', (err) => {
1313
}
1414
});
1515

16-
process.on('unhandledRejection', (reason, promise) => {
17-
logger.error({reason, promise}, 'unhandled rejection');
16+
process.on('unhandledRejection', (reason) => {
17+
try {
18+
logger.error({reason}, 'UNHANDLED REJECTION!');
19+
} catch (ignore) {
20+
console.log('UNHANDLED REJECTION!', reason);
21+
} finally {
22+
process.exit(1);
23+
}
1824
});
1925

2026
function monitor(): void {

0 commit comments

Comments
 (0)