Skip to content

Commit

Permalink
Remove the timeout handler when an request is handled.
Browse files Browse the repository at this point in the history
Fixes #14117

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <[email protected]>
  • Loading branch information
tsmaeder committed Sep 3, 2024
1 parent 4c7ffb6 commit 0dd6f04
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions dev-packages/request/src/node-request-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export interface NodeRequestOptions extends RequestOptions {
};

export class NodeRequestService implements RequestService {

protected proxyUrl?: string;
protected strictSSL?: boolean;
protected authorization?: string;
Expand Down Expand Up @@ -107,9 +106,14 @@ export class NodeRequestService implements RequestService {
opts.auth = options.user + ':' + options.password;
}

const timeoutHandler = () => {
reject('timeout');
};

const req = rawRequest(opts, async res => {
const followRedirects = options.followRedirects ?? 3;
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && followRedirects > 0 && res.headers.location) {
req.off('timeout', timeoutHandler);
this.request({
...options,
url: res.headers.location,
Expand All @@ -125,6 +129,7 @@ export class NodeRequestService implements RequestService {
});

stream.on('end', () => {
req.off('timeout', timeoutHandler);
const buffer = Buffer.concat(chunks);
resolve({
url: options.url,
Expand All @@ -146,9 +151,7 @@ export class NodeRequestService implements RequestService {
reject(err);
});

req.on('timeout', () => {
reject('timeout');
});
req.on('timeout', timeoutHandler);

if (options.timeout) {
req.setTimeout(options.timeout);
Expand Down

0 comments on commit 0dd6f04

Please sign in to comment.