Skip to content

Commit 934cf87

Browse files
authored
fix(node-http-handler)!: set maxSockets=50 by default (#2024)
1 parent 1a327c1 commit 934cf87

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,30 @@ import {
1717

1818
describe("NodeHttpHandler", () => {
1919
describe("constructor", () => {
20+
it("sets keepAlive=true by default", () => {
21+
const nodeHttpHandler = new NodeHttpHandler();
22+
expect((nodeHttpHandler as any).httpAgent.keepAlive).toEqual(true);
23+
});
24+
25+
it("sets maxSockets=50 by default", () => {
26+
const nodeHttpHandler = new NodeHttpHandler();
27+
expect((nodeHttpHandler as any).httpAgent.maxSockets).toEqual(50);
28+
});
29+
2030
it("can set httpAgent and httpsAgent", () => {
31+
let keepAlive = false;
2132
let maxSockets = Math.round(Math.random() * 50) + 1;
2233
let nodeHttpHandler = new NodeHttpHandler({
23-
httpAgent: new http.Agent({ maxSockets }),
34+
httpAgent: new http.Agent({ keepAlive, maxSockets }),
2435
});
36+
expect((nodeHttpHandler as any).httpAgent.keepAlive).toEqual(keepAlive);
2537
expect((nodeHttpHandler as any).httpAgent.maxSockets).toEqual(maxSockets);
38+
keepAlive = true;
2639
maxSockets = Math.round(Math.random() * 50) + 1;
2740
nodeHttpHandler = new NodeHttpHandler({
28-
httpsAgent: new https.Agent({ maxSockets }),
41+
httpsAgent: new https.Agent({ keepAlive, maxSockets }),
2942
});
43+
expect((nodeHttpHandler as any).httpsAgent.keepAlive).toEqual(keepAlive);
3044
expect((nodeHttpHandler as any).httpsAgent.maxSockets).toEqual(maxSockets);
3145
});
3246
});

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ export class NodeHttpHandler implements HttpHandler {
4242
this.connectionTimeout = connectionTimeout;
4343
this.socketTimeout = socketTimeout;
4444
const keepAlive = true;
45-
this.httpAgent = httpAgent || new hAgent({ keepAlive });
46-
this.httpsAgent = httpsAgent || new hsAgent({ keepAlive });
45+
const maxSockets = 50;
46+
this.httpAgent = httpAgent || new hAgent({ keepAlive, maxSockets });
47+
this.httpsAgent = httpsAgent || new hsAgent({ keepAlive, maxSockets });
4748
}
4849

4950
destroy(): void {

0 commit comments

Comments
 (0)