mirror of
https://github.com/axios/axios.git
synced 2026-04-11 02:11:50 +08:00
fix(http): closing detached http2 session on timeout (#7457)
Co-authored-by: Dmitriy Mozgovoy <robotshara@gmail.com>
This commit is contained in:
parent
fa337332b9
commit
f7a4ee21d5
@ -108,6 +108,9 @@ class Http2Sessions {
|
||||
} else {
|
||||
entries.splice(i, 1);
|
||||
}
|
||||
if (!session.closed) {
|
||||
session.close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3045,6 +3045,37 @@ describe('supports http with nodejs', function () {
|
||||
assert.strictEqual(data1, 'OK');
|
||||
assert.strictEqual(data2, 'OK');
|
||||
});
|
||||
|
||||
it('should close connection after sessionTimeout ends', async () => {
|
||||
server = await startHTTPServer(
|
||||
(req, res) => {
|
||||
setTimeout(() => res.end('OK'), 100);
|
||||
},
|
||||
{
|
||||
useHTTP2: true,
|
||||
}
|
||||
);
|
||||
|
||||
const response = await http2Axios.get(LOCAL_SERVER_URL, {
|
||||
responseType: 'stream',
|
||||
http2Options: {
|
||||
sessionTimeout: 1000,
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual(response.data.session.closed, false);
|
||||
|
||||
let sessionClosed = false;
|
||||
response.data.session.once('close', () => {
|
||||
sessionClosed = true;
|
||||
});
|
||||
|
||||
const data = await getStream(response.data);
|
||||
assert.strictEqual(data, 'OK');
|
||||
|
||||
await setTimeoutAsync(1100);
|
||||
assert.strictEqual(sessionClosed, true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user