-
-
Notifications
You must be signed in to change notification settings - Fork 11k
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
HTTP Keep-alive, "socket hang up" ECONNERR on a long-running second request #6113
Comments
We're also affected by this bug. |
Cheers! I am affected with same bug, but can only reproduce it at Node 20.10, fallback to Node 18.18 works fine. |
The cause of this issue is the way |
Same issue here. Is there any workaround except a dumb retry? |
@NaZaRKIN123 Something like this would work: axios.defaults.httpAgent = new Agent({ keepAlive: false }); |
I can confirm that the workaround provided by @snarky-puppy worked for us 🙏 |
Thanks for the detail investigation. The keepAlive is needed on my project in order to reduce latency |
+1 |
+1 |
2 similar comments
+1 |
+1 |
HTTP keepalive was enabled by default in Node 20, and is apparently causing errors for axios. See e.g. nodejs/node#47130, axios/axios#6113
This is because of #6536. Short summary: Node.js changed its default Keep-Alive behavior after Node.js 18. |
I try following code in next.js _app.tsx, but not worked: // _app.tsx
if (typeof window === 'undefined') {
/**
* @see https://github.com/axios/axios/issues/6113#issuecomment-1909291937
*/
async function fixAxiosKeepAlive() {
const { default: axios } = await import('axios');
const { Agent } = await import('https');
axios.defaults.httpAgent = new Agent({ keepAlive: false });
}
fixAxiosKeepAlive();
} Because of this issue, we have to revert from node 20 to 18, or we may try to remove the axios from our project. |
@tjx666 you should replace |
+1 |
1 similar comment
+1 |
Describe the bug
On keep-alive connections, if a timeout value is given to the first request but not on subsequent requests, the subsequent requests will eventually throw a "socket hang up" error.
To Reproduce
Code snippet
No response
Expected behavior
Axios Version
0.22.0 - 1.6.2
Adapter Version
HTTP
Browser
No response
Browser Version
No response
Node.js Version
20.9.0
OS
OSX 14
Additional Library Versions
No response
Additional context/Screenshots
The text was updated successfully, but these errors were encountered: