Skip to content

"Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client" with AWS SDK #16438

@devunt

Description

@devunt

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

9.24.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

Stacktrace:

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
  at ClientRequest.setHeader (node:_http_outgoing:642:11)
  at SentryHttpInstrumentation._onOutgoingRequestCreated (/Users/finn/workspaces/typie/node_modules/.pnpm/@sentry+node@9.24.0/node_modules/@sentry/node/src/integrations/http/SentryHttpInstrumentation.ts:265:15)
  at onHttpClientRequestCreated (/Users/finn/workspaces/typie/node_modules/.pnpm/@sentry+node@9.24.0/node_modules/@sentry/node/src/integrations/http/SentryHttpInstrumentation.ts:167:12)
  at Channel.publish (node:diagnostics_channel:150:9)
  at new ClientRequest (node:_http_client:384:35)
  at request (node:https:381:10)
  at /Users/finn/workspaces/typie/node_modules/.pnpm/@smithy+node-http-handler@4.0.6/node_modules/@smithy/node-http-handler/dist-cjs/index.js:366:19
  at new Promise (<anonymous>)
  at _NodeHttpHandler.handle (/Users/finn/workspaces/typie/node_modules/.pnpm/@smithy+node-http-handler@4.0.6/node_modules/@smithy/node-http-handler/dist-cjs/index.js:300:12)
  at /Users/finn/workspaces/typie/node_modules/.pnpm/@smithy+smithy-client@4.4.1/node_modules/@smithy/smithy-client/dist-cjs/index.js:155:35 {
code: 'ERR_HTTP_HEADERS_SENT'

Sentry initialization:

Sentry.init({
  dsn: "<actual dsn>",
});

Code that causes trouble:

      await aws.s3.send(
        new PutObjectCommand({
          Bucket: '<bucket name>',
          Key: `<some key>`,
          Body: <buffer>,
        }),
      );

package.json:

"@aws-sdk/client-s3": "^3.812.0",
"@sentry/node": "^9.24.0",

node -v:

v24.1.0

As a temporary workaround, setting tracePropagationTargets: [] solves the issue.

Expected Result

Code works well.

Actual Result

It does not.

Activity

moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jun 1, 2025
andreiborza

andreiborza commented on Jun 2, 2025

@andreiborza
Member

Hi @devunt, thanks for filing this.

I tried to replicate this here but couldn't. Could you please provide a reproduction repo or try to see what's different from mine?

moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jun 2, 2025
mzoellner-sc

mzoellner-sc commented on Jun 3, 2025

@mzoellner-sc

Running into the same issue on a few projects. It looks like this was introduced in 9.23.0.

The error bubbles all the way up as an uncaught exception.

moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jun 3, 2025
andreiborza

andreiborza commented on Jun 3, 2025

@andreiborza
Member

@mzoellner-sc thank you. Are you doing anything different from my attempt to reproduce here? Any chance you could share a reproduction?

moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jun 3, 2025
devunt

devunt commented on Jun 3, 2025

@devunt
Author

Hi @andreiborza, My code had sent GetObject command a few lines before the issue-causing PutObject command. I'll prepare the reproduction code.

15 remaining items

moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jun 3, 2025
itsjgf

itsjgf commented on Jun 3, 2025

@itsjgf

@andreiborza Wouldn’t it be better to downgrade Sentry to 9.22.0? As others have mentioned above, the error bubbles up as an uncaught exception and, in our case, this is causing our pods to restart.

moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jun 3, 2025
andreiborza

andreiborza commented on Jun 3, 2025

@andreiborza
Member

The problem exists in 9.22.0 as well (if you completely disable spans) which is why I recommended downgrading node instead. That being said, if downgrading to 9.22.0 works for your case, that's an easier downgrade.

moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jun 3, 2025
added a commit that references this issue on Jun 3, 2025
b1d5b9e
added a commit that references this issue on Jun 4, 2025
a08cae2
github-actions

github-actions commented on Jun 4, 2025

@github-actions
Contributor

A PR closing this issue has just been released 🚀

This issue was referenced by PR #16473, which was included in the 9.26.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @devunt@itsjgf@andreiborza@mzoellner-sc

      Issue actions

        "Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client" with AWS SDK · Issue #16438 · getsentry/sentry-javascript