2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-11 18:02:32 +03:00

fix(http2): fix possible race condition when handling http2 stream on almost timed out session by improving timeout out algorithm; (#7186)

This commit is contained in:
Dmitriy Mozgovoy
2025-10-27 00:46:40 +02:00
committed by GitHub
parent 08db960d9f
commit d000fbfd07
2 changed files with 62 additions and 21 deletions
+16 -11
View File
@@ -2423,7 +2423,7 @@ describe('supports http with nodejs', function () {
});
it('should support request cancellation', async function (){
if (typeof AbortSignal !== 'function') {
if (typeof AbortSignal !== 'function' || !AbortSignal.timeout) {
this.skip();
}
@@ -2525,13 +2525,17 @@ describe('supports http with nodejs', function () {
it("should use different sessions for different authorities", async() => {
server = await startHTTPServer((req, res) => {
setTimeout(() => res.end('OK'), 1000);
setTimeout(() => {
res.end('OK');
}, 2000);
}, {
useHTTP2: true
});
server2 = await startHTTPServer((req, res) => {
setTimeout(() => res.end('OK'), 1000);
setTimeout(() => {
res.end('OK');
}, 2000);
}, {
useHTTP2: true,
port: SERVER_PORT2
@@ -2559,7 +2563,9 @@ describe('supports http with nodejs', function () {
it("should use different sessions for requests with different http2Options set", async() => {
server = await startHTTPServer((req, res) => {
setTimeout(() => res.end('OK'), 1000);
setTimeout(() => {
res.end('OK')
}, 1000);
}, {
useHTTP2: true
});
@@ -2639,6 +2645,8 @@ describe('supports http with nodejs', function () {
}
});
const data1 = await getStream(response1.data);
await setTimeoutAsync(5000);
const response2 = await http2Axios.get(LOCAL_SERVER_URL, {
@@ -2648,15 +2656,12 @@ describe('supports http with nodejs', function () {
}
});
const data2 = await getStream(response2.data);
assert.notStrictEqual(response1.data.session, response2.data.session);
assert.deepStrictEqual(
await Promise.all([
getStream(response1.data),
getStream(response2.data)
]),
['OK', 'OK']
);
assert.strictEqual(data1, 'OK');
assert.strictEqual(data2, 'OK');
});
});
});