-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't prevent Sentry SDK from exiting the process even with onFatalError #1661
Comments
@dj-hedgehog Does this help? |
If you want to have a complete control over it, you have to turn off this integration and add handler yourself. Sentry.init({
dsn: 'https://key@mysentry.mycompany/2',
integrations(integrations) {
return integrations.filter(integration => integration.id !== 'OnUncaughtException')
}
});
global.process.on('uncaughtException', (error) => {
const hub = Sentry.getCurrentHub();
hub.withScope(async (scope) => {
scope.setLevel('fatal');
hub.captureException(error, { originalException: error });
});
}); |
@kamilogorek Thank you for your quick response. The following code exits the app after the first throw nonetheless:
|
@dj-hedgehog it should be |
That solved the issue, thanks a lot :) |
I just ran into this. It would be wonderful to document the intent spelled out by @kamilogorek somewhere. Maybe here?: https://docs.sentry.io/platforms/node/configuration/integrations/default-integrations/#onuncaughtexception |
I hate to necrobump this 2018 issue, but I just ran into this in 2022 and it was very surprising to have my applications behavior changed by the use of Sentry like this. It also cost me several hours of hair pulling out trying to figure out what was happening. I have always thought one of the design goals of Sentry is to have no meaningful side effects. Any maintainers care to comment? |
What was exactly your case? We are following all the defaults from node's implementation written down in the docs - https://nodejs.org/api/process.html#event-uncaughtexception We also had no reports of this being not an intended behavior in almost 4 years, thus my question here. cc @getsentry/team-web-backend |
Hi @kamilogorek, This is in the context of an electron app which also registers and handles I think maybe sentry is assuming that there is no other listener and doing what node would do in that case, ie. exit. Just a thought, but with node 13+ they have https://nodejs.org/api/process.html#event-uncaughtexceptionmonitor Works for promises and normal exceptions and doesn't have side effects. Almost like, how it should have been in the first place! 😄 |
We do that for browser SDK, not sure why we decide to skip it here tbh. Might be just something that we missed - sentry-javascript/packages/utils/src/instrument.ts Lines 583 to 621 in cc44957
TIL about There's a possibility that monitor will trigger events, and let it fall through to uncaughtException handler, which will in turns kill the process before letting requests out.
I'll notify the team to backlog this issue :) |
Our Node app sets a
Within the |
We could also expose an option here for full backwards compatibility. Re-opening and adding to the backlog. PRs welcome! |
Not sure if that would work but we could also check for any listeners using |
…ception' or 'unhandledRejection' listener - Fixes getsentry#1661
PR here #5176 |
…ception' or 'unhandledRejection' listener - Fixes getsentry#1661
Just ran into this same problem. It is extremely annoying and frustrating! I had to do a lot of digging just to find this issue regarding it. Please fix this 🙏🏻 |
The same problem |
Related: #4154 |
Related: #6146 |
same problem here, as it stands currently sentry is not usable for us |
As per the Node docs if an unhandled rejection is triggered the process should be exited: https://nodejs.org/api/process.html#warning-using-uncaughtexception-correctly.
If you want to override Node's recommendation, you can override this via the Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: integrations => {
return integrations.map(integration => {
if (integration.name === 'OnUncaughtException') {
// override `OnUncaughtException` integration to not exit.
return new Sentry.Integrations.OnUncaughtException({
// do not exit if other uncaught exception handlers are registered.
exitEvenIfOtherHandlersAreRegistered: false,
});
} else {
return integration;
}
});
},
}); In a future major version we will make this API better. Thanks! |
I tried getting
Since this means a lot of effort for arguably little gain (and potentially many more pitfalls), I think we will stick with the current approach for now. |
I am gonna mark this as resolved with #11532. This will be shipped as a breaking change as part of the upcoming major v8 release. Please see the migration docs here: https://github.com/getsentry/sentry-javascript/blob/develop/MIGRATION.md#behaviour-in-combination-with-onuncaughtexception-handlers-in-nodejs As always, feel free to ping us here for any questions or concerns! |
@sentry/node version: 4.1.1
Node.js version: 10.9.0
Sentry exits my process after an uncaught exception even I provide my own implementation of onFatalError. How can I prevent that?
Here is a minimal working example. Without
sentry.init
I get to the 2nd throw. With it the process finisches after the 1st one.The text was updated successfully, but these errors were encountered: