Skip to content

Uncaught async middleware error crashing server #6689

Closed as not planned
Closed as not planned
@sderrow

Description

@sderrow

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/node

SDK Version

7.29.0

Framework Version

No response

Link to Sentry event

No response

Steps to Reproduce

Here's a CodeSandbox demo of the situation.

Brief summary:
I'm using express-async-errors in order to catch errors that are thrown in async handler and automatically forward to next. This was working fine through sentry-javascript version 7.11.1 (Aug 2022). Starting with 7.12.0 up to the latest release (7.29.0), Sentry's wrappers are somehow overwriting the auto-forwarding of thrown errors in async middleware, so any errors are uncaught and crash the server. Furthermore, the behavior is not even consistent. If the async middleware is added directly as part of a route declaration, then errors within that middleware will still be forwarded. It's only when the middleware is added to an entire express router (see the CodeSandbox demo).

Expected Result

Ideally, Sentry's SDK would not interfere with express-async-errors so that errors thrown in async middleware can be caught and forwarded to next. But at a minimum, the behavior should be consistent between router and route middlewares.

Actual Result

Server is crashed when errors are thrown in async middleware preceding routers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nodeIssues related to the Sentry Node SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions