fix(http): closing detached http2 session on timeout (#7457)

Co-authored-by: Dmitriy Mozgovoy <robotshara@gmail.com>
This commit is contained in:
Dmitriy Fedotov 2026-03-06 23:50:51 +02:00 committed by GitHub
parent fa337332b9
commit f7a4ee21d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 0 deletions

View File

@ -108,6 +108,9 @@ class Http2Sessions {
} else {
entries.splice(i, 1);
}
if (!session.closed) {
session.close();
}
return;
}
}

View File

@ -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);
});
});
});