mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +03:00
fix(http): closing detached http2 session on timeout (#7457)
Co-authored-by: Dmitriy Mozgovoy <robotshara@gmail.com>
This commit is contained in:
@@ -108,6 +108,9 @@ class Http2Sessions {
|
|||||||
} else {
|
} else {
|
||||||
entries.splice(i, 1);
|
entries.splice(i, 1);
|
||||||
}
|
}
|
||||||
|
if (!session.closed) {
|
||||||
|
session.close();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3045,6 +3045,37 @@ describe('supports http with nodejs', function () {
|
|||||||
assert.strictEqual(data1, 'OK');
|
assert.strictEqual(data1, 'OK');
|
||||||
assert.strictEqual(data2, '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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user