Skip to content

[BUG] Error: Cannot set headers after they are sent to the client #244

@pflannery

Description

@pflannery

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Error Message

Error: Cannot set headers after they are sent to the client
	at new NodeError (node:internal/errors:405:5)
	at ClientRequest.setHeader (node:_http_outgoing:648:11)
	at Agent.addRequest (c:\Users\xxx\.vscode\extensions\pflannery.vscode-versionlens-1.11.0\node_modules\@npmcli\agent\lib\agents.js:178:13)
	at c:\Program Files\Microsoft VS Code\resources\app\node_modules.asar\agent-base\dist\index.js:77:31

A couple of users of my vscode extension versionlens have recently experienced this issue

Versionlens uses [email protected]. I tracked down this error to be related to a sub dependency of this package @npmcli/agent v2.2.2 which got installed in a recent update via the versionlens package-lock.json file.

The error occurs here

When the users rolled back versionlens they reported the error had gone away but the version they rolled back to also uses [email protected] so its a sub dependency update that is causing the problem.

I'm not sure how to recreate the issue as I can't seem to hit the line of code with the error so it seems to be npm config specific.

I'm wondering if the solution is as simple as adding a check

if (!request.headers.has('connection')) {
    request.headers.set('connection', agent ? 'keep-alive' : 'close')
  }

Expected Behavior

No errors

Steps To Reproduce

No response

Environment

  • npm: 10.2.4
  • Node: v18.19.1
  • OS: Windows_NT x64 10.0.19045

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds an initial review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions