-
-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Closed
Closed
Copy link
Labels
Description
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
const http = require('http');
const axios = require('axios');
describe('socket hang up', () => {
let server;
beforeAll(done => {
server = http.createServer(async (req, res) => {
if (req.url === '/wait') {
await new Promise(resolve => setTimeout(resolve, 5000));
}
res.end('ok');
});
server.listen(3000, done);
});
afterAll(done => {
server.close(done);
});
it('will fail with "socket hang up"', async () => {
const baseURL = `http://localhost:3000`;
await axios.get('/1', {baseURL, timeout: 1000});
await axios.get(`/wait`, {baseURL, timeout: 0});
}, 15000);
});Code snippet
No response
Expected behavior
- "socket hang up" is misleading because it indicates the server closed the connection (in this bug the opposite is true)
- One would not expect that a timeout would keep running after a request has completed. This is a (quite major IMO) footgun.
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

LarsLaw, avermeil, LarsOL, sfc-gh-dszmolka, archisdi and 19 more