[Console] Add context to client request timeout (#206742)

This commit is contained in:
Ignacio Rivas 2025-01-17 09:49:30 +01:00 committed by GitHub
parent a514c26d38
commit 8be69aa77f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 3 deletions

View file

@ -55,12 +55,18 @@ describe(`Console's send request`, () => {
destroy: sinon.stub(),
on() {},
once() {},
protocol: 'http:',
host: 'nowhere.none',
method: 'POST',
path: '/_bulk',
} as any;
try {
await sendProxyRequest({ timeout: 0 }); // immediately timeout
fail('Should not reach here!');
} catch (e) {
expect(e.message).toEqual('Client request timeout');
expect(e.message).toEqual(
'Client request timeout for: http://nowhere.none with request POST /_bulk'
);
expect((fakeRequest.destroy as sinon.SinonStub).calledOnce).toBe(true);
}
});

View file

@ -55,12 +55,13 @@ export const proxyRequest = ({
finalUserHeaders.host = hostname;
}
const parsedPort = port === '' ? undefined : parseInt(port, 10);
const req = client.request({
method: method.toUpperCase(),
// We support overriding this on a per request basis to support legacy proxy config. See ./proxy_config.
rejectUnauthorized: typeof rejectUnauthorized === 'boolean' ? rejectUnauthorized : undefined,
host: sanitizeHostname(hostname),
port: port === '' ? undefined : parseInt(port, 10),
port: parsedPort,
protocol,
path: `${pathname}${search || ''}`,
headers: {
@ -96,7 +97,12 @@ export const proxyRequest = ({
req.destroy();
}
if (!resolved) {
timeoutReject(Boom.gatewayTimeout('Client request timeout'));
const request = `${req.method} ${req.path}`;
const requestPath = `${req.protocol}//${req.host}${parsedPort ? `:${parsedPort}` : ''}`;
timeoutReject(
Boom.gatewayTimeout(`Client request timeout for: ${requestPath} with request ${request}`)
);
} else {
timeoutResolve(undefined);
}