Skip to content

The onUnhandledRejectionIntegration does not exit gracefully in strict mode #12266

Closed
@WesCossick

Description

@WesCossick

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.5.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

const sentryConfig: Sentry.NodeOptions = {
	dsn: process.env.SENTRY_DSN,
	environment: process.env.ENVIRONMENT,
	integrations: [
		Sentry.onUnhandledRejectionIntegration({
			mode: 'strict',
		}),
	],
};

Sentry.init(sentryConfig);

Steps to Reproduce

Trigger an unhandled promise rejection while using the onUnhandledRejectionIntegration in mode: 'strict'.

Expected Result

For the app to exit gracefully.

Actual Result

When Sentry's onUnhandledRejectionIntegration catches an unhandled promise rejection in strict mode, it is currently designed to exit immediately:

This does not allow the app to shut things down and exit gracefully, because it bypasses any SIGTERM listeners. The code should really be designed like so:

if (process.listenerCount('SIGTERM')) {
  global.process.kill(process.pid, 'SIGTERM');
} else {
  global.process.exit(1);
}

This will detect if there are any SIGTERM listeners, and if so, rely on those to handle shut down and exit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nodeIssues related to the Sentry Node SDK

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions