Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
skrtheboss opened this issue Nov 18, 2024 · 0 comments

Comments

@skrtheboss
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant