Skip to content

Commit efc829a

Browse files
committed
chore: added connectionTimeout for stream
1 parent eca1400 commit efc829a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,17 @@ export class NodeHttp2Handler
6666

6767
req.on("error", reject);
6868

69-
// TODO: wire-up any timeout logic
69+
const { connectionTimeout } = this.httpOptions;
70+
if (connectionTimeout) {
71+
req.setTimeout(connectionTimeout, () => {
72+
req.close();
73+
const timeoutError = new Error(
74+
`Stream timed out because of no activity for ${connectionTimeout} ms`
75+
);
76+
timeoutError.name = "TimeoutError";
77+
reject(timeoutError);
78+
});
79+
}
7080
// TODO: wire-up any abort logic
7181

7282
writeRequestBody(req, request);

0 commit comments

Comments
 (0)