Skip to content

Commit 38f5a85

Browse files
sampaiodiegoggazzo
authored andcommitted
fix: improve error handling no ddp-streamer (RocketChat#36105)
Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com>
1 parent d52d331 commit 38f5a85

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

.changeset/fast-dolphins-run.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@rocket.chat/ddp-streamer': patch
3+
'@rocket.chat/meteor': patch
4+
---
5+
6+
Fixes an issue that was causing ddp-streamer process to break if the communication with presence service was interrupted for any reason.

ee/apps/ddp-streamer/src/service.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,39 @@ import { startTracing } from '@rocket.chat/tracing';
3232

3333
await api.start();
3434
})();
35+
36+
/**
37+
* If some promise is rejected and doesn't have a catch (unhandledRejection) it may cause the process to exit.
38+
*
39+
* Since unhandled rejections are deprecated in NodeJS:
40+
* (node:83382) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections
41+
* that are not handled will terminate the Node.js process with a non-zero exit code.
42+
* we will start respecting this and exit the process to prevent these kind of problems.
43+
*/
44+
45+
process.on('unhandledRejection', (error) => {
46+
console.error('=== UnHandledPromiseRejection ===');
47+
console.error(error);
48+
console.error('---------------------------------');
49+
console.error(
50+
'Setting EXIT_UNHANDLEDPROMISEREJECTION will cause the process to exit allowing your service to automatically restart the process',
51+
);
52+
console.error('Future node.js versions will automatically exit the process');
53+
console.error('=================================');
54+
55+
if (process.env.TEST_MODE || process.env.NODE_ENV === 'development' || process.env.EXIT_UNHANDLEDPROMISEREJECTION) {
56+
process.exit(1);
57+
}
58+
});
59+
60+
process.on('uncaughtException', async (error) => {
61+
console.error('=== UnCaughtException ===');
62+
console.error(error);
63+
console.error('-------------------------');
64+
console.error('Errors like this can cause oplog processing errors.');
65+
console.error('===========================');
66+
67+
if (process.env.TEST_MODE || process.env.NODE_ENV === 'development' || process.env.EXIT_UNHANDLEDPROMISEREJECTION) {
68+
process.exit(1);
69+
}
70+
});

0 commit comments

Comments
 (0)