Skip to content

ERR_STREAM_WRITE_AFTER_END #6099

Closed as not planned
Closed as not planned
@jessehansen

Description

@jessehansen

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

SDK Version

7.17.2

Framework Version

NextJS 12.3.1

Link to Sentry event

No response

Steps to Reproduce

We're using Sentry with Next.JS on Vercel. Last week we updated from @sentry/nextjs version 7.13.0 to 7.16.0, and we started seeing some requests to API endpoints returning 500 errors without any corresponding events in Sentry. We have since updated to @sentry/[email protected] and are getting the same errors. The Function logs on Vercel show up with an error message for ERR_STREAM_WRITE_AFTER_END.

Additional Info:

  • Node Version: 16.16.0
  • Webpack version: 5.73.0

We tried removing all of the wrapping withSentry calls from our API routes, but it didn't stop these errors.

Expected Result

No internal stream errors output to Vercel's function logs.

Actual Result

(Line Breaks added for readability)

2022-10-31T19:44:11.763Z	44cbcf3d-c3f9-48cf-8aa2-659e324a5ed5	ERROR	Uncaught Exception 	
{"errorType":"Error",
"errorMessage":"write after end",
"trace":
["Error [ERR_STREAM_WRITE_AFTER_END]: write after end",
"    at new NodeError (node:internal/errors:372:5)",
"    at ServerResponse.end (node:_http_outgoing:846:15)",
"    at ServerResponse.apiRes.end (/var/task/node_modules/next/dist/server/api-utils/node.js:346:25)",
"    at ServerResponse.sentryWrappedEnd [as end] (/var/task/node_modules/@sentry/nextjs/cjs/config/wrappers/utils/responseEnd.js:29:22)",
"    at processTicksAndRejections (node:internal/process/task_queues:96:5)"]}
Unknown application error occurred

I believe this to be related to #4151

Metadata

Metadata

Assignees

Labels

Package: nextjsIssues related to the Sentry Nextjs SDK

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions