[Console] Cancel http request to es on timeout (#135610)

* [Console] Cancel http request to es on timeout

* Update proxyRequest.test

Co-authored-by: Muhammad Ibragimov <muhammad.ibragimov@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Muhammad Ibragimov 2022-07-06 15:53:25 +05:00 committed by GitHub
parent fd50544641
commit b8599a8470
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View file

@ -31,7 +31,7 @@ describe(`Console's send request`, () => {
it('correctly implements timeout and abort mechanism', async () => {
fakeRequest = {
abort: sinon.stub(),
destroy: sinon.stub(),
on() {},
once() {},
} as any;
@ -47,7 +47,7 @@ describe(`Console's send request`, () => {
fail('Should not reach here!');
} catch (e) {
expect(e.message).toEqual('Client request timeout');
expect((fakeRequest.abort as sinon.SinonStub).calledOnce).toBe(true);
expect((fakeRequest.destroy as sinon.SinonStub).calledOnce).toBe(true);
}
});

View file

@ -113,7 +113,10 @@ export const proxyRequest = ({
const timeoutPromise = new Promise<any>((timeoutResolve, timeoutReject) => {
setTimeout(() => {
if (!req.aborted && !req.socket) req.abort();
// Destroy the stream on timeout and close the connection.
if (!req.destroyed) {
req.destroy();
}
if (!resolved) {
timeoutReject(Boom.gatewayTimeout('Client request timeout'));
} else {