Skip to content

Compatibility with Node.js 22 and Axios: Data after "Connection: close" error #346

@skrtheboss

Description

@skrtheboss

In Node.js 22, the llhttp library introduced a breaking change by modifying its default behavior. A new check for "data after close" has been added, which causes unexpected failures when using the proxy-agents library in certain configurations.

Problem:

When using the latest version of Node.js (22) in combination with:

  • axios
  • http-proxy-agent
  • proxy-chain (which listens to clientError events as seen here)

All requests fail with a Data after "Connection: close" error.

Observations:

The issue seems to arise because headers are sent twice during the request. Below is an example:

POST http://[::]:33155/ HTTP/1.1
Accept: application/json, text/plain, */*
Content-Type: application/json
User-Agent: axios/1.7.7
Content-Length: 11
Accept-Encoding: gzip, compress, deflate, br
Host: [::]:33155
Proxy-Connection: close
Connection: close

{"test":55}POST http://[::]:33155/ HTTP/1.1
Accept: application/json, text/plain, */*
Content-Type: application/json
User-Agent: axios/1.7.7
Content-Length: 11
Accept-Encoding: gzip, compress, deflate, br
Host: [::]:33155
Proxy-Connection: close
Connection: close


HTTP/1.1 400 Bad Request

This behavior has existed in earlier Node.js versions but did not cause failures. With Node.js 22, however, the new llhttp checks result in the request being rejected.

Potential Solution:

I have created a branch to reproduce the issue and explore a potential fix: Branch: fix/test-node-22.

In this branch, I added a workaround that prevents headers from being sent twice. However, I am not entirely sure about the necessity of certain calls within the code. Additional input and review would be highly appreciated to verify the solution and ensure it aligns with the library's intended functionality.

Let me know if you need any more information or clarification. I’d be happy to provide additional details or assist with further testing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions