2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-08 17:22:34 +03:00

fix(http): fix 'socket hang up' bug for keep-alive requests when using timeouts; (#7206)

This commit is contained in:
Dmitriy Mozgovoy
2025-11-04 01:08:35 +02:00
committed by GitHub
parent 12c314b603
commit 8d372335f5
2 changed files with 18 additions and 0 deletions
+3
View File
@@ -858,6 +858,9 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
req
));
});
} else {
// explicitly reset the socket timeout value for a possible `keep-alive` request
req.setTimeout(0);
}
+15
View File
@@ -2682,6 +2682,21 @@ describe('supports http with nodejs', function () {
assert.strictEqual(await getStream(err.response.data), 'OK');
}
});
describe('keep-alive', () => {
it('should not fail with "socket hang up" when using timeouts', async () => {
server = await startHTTPServer(async (req, res) => {
if (req.url === '/wait') {
await new Promise(resolve => setTimeout(resolve, 5000));
}
res.end('ok');
})
const baseURL = LOCAL_SERVER_URL;
await axios.get('/1', {baseURL, timeout: 1000});
await axios.get(`/wait`, {baseURL, timeout: 0});
}, 15000);
});
});