Skip to content

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

Open
@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/@[email protected]/node_modules/@sentry/node/src/integrations/http/SentryHttpInstrumentation.ts:265:15)
  at onHttpClientRequestCreated (/Users/finn/workspaces/typie/node_modules/.pnpm/@[email protected]/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/@[email protected]/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/@[email protected]/node_modules/@smithy/node-http-handler/dist-cjs/index.js:300:12)
  at /Users/finn/workspaces/typie/node_modules/.pnpm/@[email protected]/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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions