Skip to content

Commit 79c46f3

Browse files
authored
fix(node-http-handler): undeprecate connectionTimeout (#4669)
1 parent 33501ba commit 79c46f3

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

packages/node-http-handler/src/node-http-handler.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,31 @@ import { Agent as hsAgent, request as hsRequest, RequestOptions } from "https";
66

77
import { NODEJS_TIMEOUT_ERROR_CODES } from "./constants";
88
import { getTransformedHeaders } from "./get-transformed-headers";
9+
import { setConnectionTimeout } from "./set-connection-timeout";
10+
import { setSocketTimeout } from "./set-socket-timeout";
911
import { writeRequestBody } from "./write-request-body";
1012

1113
/**
1214
* Represents the http options that can be passed to a node http client.
1315
*/
1416
export interface NodeHttpHandlerOptions {
1517
/**
16-
* @deprecated Use {@link requestTimeout}
17-
*
18-
* Note:{@link NodeHttpHandler} will resolve request timeout via nullish coalescing the following fields:
19-
* {@link requestTimeout} ?? {@link connectionTimeout} ?? {@link socketTimeout} ?? {@link DEFAULT_REQUEST_TIMEOUT}
20-
*
2118
* The maximum time in milliseconds that the connection phase of a request
2219
* may take before the connection attempt is abandoned.
20+
*
21+
* Defaults to 0, which disables the timeout.
2322
*/
2423
connectionTimeout?: number;
2524

2625
/**
27-
* The maximum time in milliseconds that the connection phase of a request
28-
* may take before the connection attempt is abandoned.
26+
* The number of milliseconds a request can take before automatically being terminated.
27+
* Defaults to 0, which disables the timeout.
2928
*/
3029
requestTimeout?: number;
3130

3231
/**
3332
* @deprecated Use {@link requestTimeout}
3433
*
35-
* Note:{@link NodeHttpHandler} will resolve request timeout via nullish coalescing the following fields:
36-
* {@link requestTimeout} ?? {@link connectionTimeout} ?? {@link socketTimeout} ?? {@link DEFAULT_REQUEST_TIMEOUT}
37-
*
3834
* The maximum time in milliseconds that a socket may remain idle before it
3935
* is closed.
4036
*/
@@ -45,9 +41,8 @@ export interface NodeHttpHandlerOptions {
4541
}
4642

4743
interface ResolvedNodeHttpHandlerConfig {
48-
requestTimeout: number;
44+
requestTimeout?: number;
4945
connectionTimeout?: number;
50-
socketTimeout?: number;
5146
httpAgent: hAgent;
5247
httpsAgent: hsAgent;
5348
}
@@ -82,8 +77,7 @@ export class NodeHttpHandler implements HttpHandler {
8277

8378
return {
8479
connectionTimeout,
85-
socketTimeout,
86-
requestTimeout: requestTimeout ?? connectionTimeout ?? socketTimeout ?? DEFAULT_REQUEST_TIMEOUT,
80+
requestTimeout: requestTimeout ?? socketTimeout,
8781
httpAgent: httpAgent || new hAgent({ keepAlive, maxSockets }),
8882
httpsAgent: httpsAgent || new hsAgent({ keepAlive, maxSockets }),
8983
};
@@ -142,11 +136,9 @@ export class NodeHttpHandler implements HttpHandler {
142136
}
143137
});
144138

145-
const timeout: number = this.config?.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT;
146-
req.setTimeout(timeout, () => {
147-
req.destroy();
148-
reject(Object.assign(new Error(`Connection timed out after ${timeout} ms`), { name: "TimeoutError" }));
149-
});
139+
// wire-up any timeout logic
140+
setConnectionTimeout(req, reject, this.config.connectionTimeout);
141+
setSocketTimeout(req, reject, this.config.requestTimeout);
150142

151143
// wire-up abort logic
152144
if (abortSignal) {

0 commit comments

Comments
 (0)