Skip to content

Commit c062481

Browse files
committed
chore: added http2 sessionTimeout
1 parent c41e258 commit c062481

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import {
77
HttpHandlerOptions,
88
HttpRequest,
99
HttpResponse,
10-
NodeHttpOptions
10+
NodeHttp2Options
1111
} from "@aws-sdk/types";
1212

1313
import { writeRequestBody } from "./write-request-body";
1414
import { getTransformedHeaders } from "./get-transformed-headers";
1515

1616
export class NodeHttp2Handler
17-
implements HttpHandler<Readable, NodeHttpOptions> {
17+
implements HttpHandler<Readable, NodeHttp2Options> {
1818
private readonly connectionPool: Map<string, ClientHttp2Session>;
1919

20-
constructor(private readonly httpOptions: NodeHttpOptions = {}) {
20+
constructor(private readonly http2Options: NodeHttp2Options = {}) {
2121
this.connectionPool = new Map<string, ClientHttp2Session>();
2222
}
2323

@@ -33,8 +33,6 @@ export class NodeHttp2Handler
3333
{ abortSignal }: HttpHandlerOptions
3434
): Promise<HttpResponse<Readable>> {
3535
return new Promise((resolve, reject) => {
36-
const { connectionTimeout, socketTimeout } = this.httpOptions;
37-
3836
// if the request was already aborted, prevent doing extra work
3937
if (abortSignal && abortSignal.aborted) {
4038
const abortError = new Error("Request aborted");
@@ -76,16 +74,19 @@ export class NodeHttp2Handler
7674
}
7775

7876
private getSession(authority: string): ClientHttp2Session {
79-
const existingSession = this.connectionPool.get(authority);
77+
const connectionPool = this.connectionPool;
78+
const existingSession = connectionPool.get(authority);
8079
if (existingSession) return existingSession;
8180

8281
const newSession = connect(authority);
83-
this.connectionPool.set(authority, newSession);
84-
if (this.httpOptions.connectionTimeout) {
85-
newSession.setTimeout(
86-
this.httpOptions.connectionTimeout,
87-
this.connectionPool.delete.bind(this.connectionPool, authority)
88-
);
82+
connectionPool.set(authority, newSession);
83+
84+
const { sessionTimeout } = this.http2Options;
85+
if (sessionTimeout) {
86+
newSession.setTimeout(sessionTimeout, () => {
87+
newSession.close();
88+
connectionPool.delete(authority);
89+
});
8990
}
9091
return newSession;
9192
}

packages/types/src/http.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,11 @@ export interface NodeHttpOptions extends HttpOptions {
175175
*/
176176
socketTimeout?: number;
177177
}
178+
179+
export interface NodeHttp2Options extends HttpOptions {
180+
/**
181+
* The maximum time in milliseconds that a Http2Session may remain idle before
182+
* it is closed
183+
*/
184+
sessionTimeout?: number;
185+
}

0 commit comments

Comments
 (0)