-
-
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
nextjs: Network socket closes before events are being flushed on Vercel #14780
Comments
Hy, thanks for reporting this and also pinning down the version where this fails. |
@Yuripetusko can't reproduce this, maybe there is a configuration issue. Can you provide a reproduction repository so we can better debug this? |
Thanks for looking into it. I will re-test soon, as we discovered another issue that could have been the source of this problem all along. When using turbo as a build tool, you need to set env vars in turbo config to be exposed during build time, otherwise the values can be cached for previous builds so they are incorrect or undefined. and we were using process.env.VERCEL_ENV to conditionally enable sentry on production only. So will re-test with the latest sentry version of this is now fixed as we specified required env vars |
Just double checked this. Exactly the same code reports the api route error on I will provide a reproduction soon |
Ok while preparing a reproducable example I discovered that an additional component is required to reproduce this issue, which is node 20.x on vercel. It works with node 22.x and latest version of @sentry/nextjs. While with node 20.x it works only with version 8.34.0 or below. |
Here's a reproduction. You can try deploying it on vercel with node 20.x and 22.x and see that 20.x doesn't work unless you downgrade sentry/nextjs version https://github.com/Yuripetusko/sentry-14780-issue-reproduction |
@Yuripetusko thanks for putting your effort into pinning this down. I looked into this today and found no reliable way of reproducing it, but nevertheless I was able to reproduce it sometimes. For me the node runtime had no impact, I was able to run into this in both 20 and 22. The underlying issue probably that the vercel lambda runtime closes before the event gets flushed. I reached out to vercel already regarding this. I wasn't able to reproduce it prior to v8.36 so it this very likely surfaced with our switch to Next.js OTEL performance monitoring in #13889. |
Thanks. We actually can reproduce it 100% of the time, but only on api route handlers or server actions (edge and node), but on client it works fine. So hence we suspect something about route wrapper and instrumentation. When I deploy this PR on vercel with node 20 it happens every time that errors are not caputred on sentry and with node 22 they are captured every time 🤔 For now we'll just update to node 22 so it's not a huge deal for us, but maybe relevant for other users |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nextjs
SDK Version
8.42.0
Framework Version
react 18.3.1, next 14.2.4
Link to Sentry event
No response
Reproduction Example/SDK Setup
// apps/api/sentry-example-api/route.ts
Steps to Reproduce
@sentry/nextjs
introduced a bug in version8.36.0
that broke the auto instrumentation of nextjs api route handlers in next 14.2.4 (maybe other version too) App router.The error in api route handler is not logged in sentry completly, and as soon as I downgrade to
8.33.0
it works fine. All version from8.36.0
and up to the latest (8.42.0
) have this bug.Haven't investigated this deeper, but from a quick glance, perhaps this commit was when the issue was introduced?
#14084
Or this f9df1b4
Expected Result
For
next: 14.2.4
api route handler unhandled error to be reported in sentry with latest @sentry/nextjs sdkActual Result
No error reported in Sentry
The text was updated successfully, but these errors were encountered: