Skip to content
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

Node: custom onFatalError does not work #1925

Closed
4 of 8 tasks
OliverJAsh opened this issue Feb 25, 2019 · 10 comments
Closed
4 of 8 tasks

Node: custom onFatalError does not work #1925

OliverJAsh opened this issue Feb 25, 2019 · 10 comments
Assignees

Comments

@OliverJAsh
Copy link
Contributor

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:

Version:

4.6.3

Description

I am providing a custom onFatalError to Sentry for Node:

import * as Sentry from '@sentry/node';

const options: Sentry.NodeOptions = {
  // …
  onFatalError: error => {
    console.error('Test onFatalError')
    console.error(error)
  },
  // …
};
Sentry.init(options);

However, when a fatal exception occurs, the default handler is used instead.

I stepped into the code and discovered that when we construct OnUncaughtException, we forget to pass in options:

https://github.com/getsentry/sentry-javascript/blob/4.6.3/packages/node/src/sdk.ts#L18

Thus, options.onFatalError is always undefined:

https://github.com/getsentry/sentry-javascript/blob/4.6.3/packages/node/src/integrations/onuncaughtexception.ts#L20-L23

I'm surprised TypeScript didn't catch this bug at compile time?

@OliverJAsh
Copy link
Contributor Author

Hi, do you have any thoughts on this? It's currently blocking us from upgrading.

@HazAT
Copy link
Member

HazAT commented Mar 15, 2019

@OliverJAsh Oh, good catch, we will fix this, thank you.
As a workaround you could do this:

Sentry.init({
  ...
  integrations: [
    new Sentry.Integrations.OnUncaughtException({
      onFatalError: error => {
        console.error('Test onFatalError');
        console.error(error);
      },
    }),
  ],
  ...
});

@HazAT HazAT self-assigned this Mar 15, 2019
@HazAT HazAT closed this as completed in 41c0f4e Mar 20, 2019
@MatteoGioioso
Copy link

@HazAT Hello is this fixed?

This morning we discovered a fatal error not reported by Sentry

Is this the correct setup?

Sentry.init({
  dsn: process.env.SENTRY_DNS,
  integrations: [new Sentry.Integrations.OnUncaughtException()]
});

or fatal errors must have additional configuration?

@kamilogorek
Copy link
Contributor

There's no need to attach OnUncaughtException integration, as it's default and should work just fine without it.

@MatteoGioioso
Copy link

I just tested it again and Sentry cannot caught Fatal error. I have simulated an out of memory error with the following configuration

Sentry.init({
  dsn: "https://[email protected]/id",
});

const app = express();

app.use(Sentry.Handlers.requestHandler());

// routes

app.use(Sentry.Handlers.errorHandler());

// Global error handler
app.use(function(err, req, res, next) {

Sentry version: 5.11.0

The result is that I cannot see anything logged in Sentry.

@kamilogorek
Copy link
Contributor

Can you set debug: true in your init call and see if you get any valuable logs? If not, are you able to provide a repro case for it?

@MatteoGioioso
Copy link

I think I can try to reproduce it, hopefully I am doing something wrong, should I open a new issue?

@kamilogorek kamilogorek reopened this Mar 29, 2020
@kamilogorek
Copy link
Contributor

No need , I'll reopen this one

@MatteoGioioso
Copy link

MatteoGioioso commented Mar 29, 2020

OK, I have managed to make something: https://github.com/MatteoGioioso/sentry-fatal-error
It have basically simulated an out of memory error that make the app crash.

Please, first of all make sure that I did not make any mistakes in the Sentry configuration, that is the exact config that we have on our server right now, thanks!

@kamilogorek
Copy link
Contributor

It's not a node exception in this case. It's a process crashing, which produces a core dump (if env is configured appropriately). There is no way for the VM to call any of the handlers when it's out of memory. You can easily confirm this by adding this snippet at the very start of your program. It won't trigger.

process.on('exit', (code) => {
  console.log(`About to exit with code: ${code}`);
});

Please refer to https://www.javascriptjanuary.com/blog/nodejs-postmortem-debugging-for-fun-and-production on how to debug such issues. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants