Skip to content

Commit bf9f612

Browse files
committed
chore: clear connections array on destroy
1 parent 494c8ea commit bf9f612

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,22 @@ describe(NodeHttp2Handler.name, () => {
219219
});
220220

221221
describe("destroy", () => {
222-
it("destroys sessions and clears connectionPool", async () => {
222+
it("destroys session and clears connectionPool", async () => {
223223
await nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), {});
224224

225225
// @ts-ignore: access private property
226-
const session: ClientHttp2Session = nodeH2Handler.connectionPool.get(`${protocol}//${hostname}:${port}`);
226+
const session: ClientHttp2Session = nodeH2Handler.connections[0];
227227

228228
// @ts-ignore: access private property
229229
expect(nodeH2Handler.connectionPool.size).toBe(1);
230+
// @ts-ignore: access private property
231+
expect(nodeH2Handler.connections.length).toBe(1);
230232
expect(session.destroyed).toBe(false);
231233
nodeH2Handler.destroy();
232234
// @ts-ignore: access private property
233235
expect(nodeH2Handler.connectionPool.size).toBe(0);
236+
// @ts-ignore: access private property
237+
expect(nodeH2Handler.connections.length).toBe(0);
234238
expect(session.destroyed).toBe(true);
235239
});
236240
});
@@ -429,5 +433,22 @@ describe(NodeHttp2Handler.name, () => {
429433
mockH2Server2.close();
430434
});
431435
});
436+
437+
describe("destroy", () => {
438+
it("destroys session and clears connections", async () => {
439+
await nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), {});
440+
441+
// @ts-ignore: access private property
442+
const session: ClientHttp2Session = nodeH2Handler.connections[0];
443+
444+
// @ts-ignore: access private property
445+
expect(nodeH2Handler.connections.length).toBe(1);
446+
expect(session.destroyed).toBe(false);
447+
nodeH2Handler.destroy();
448+
// @ts-ignore: access private property
449+
expect(nodeH2Handler.connections.length).toBe(0);
450+
expect(session.destroyed).toBe(true);
451+
});
452+
});
432453
});
433454
});

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class NodeHttp2Handler implements HttpHandler {
5050
}
5151

5252
destroy(): void {
53-
this.connections.forEach(this.destroySession);
53+
this.connections.forEach((session) => this.destroySession(session));
5454
this.connectionPool.clear();
5555
}
5656

@@ -199,6 +199,7 @@ export class NodeHttp2Handler implements HttpHandler {
199199
if (!session.destroyed) {
200200
session.destroy();
201201
}
202+
this.connections = this.connections.filter((s) => s !== session);
202203
}
203204

204205
/**

0 commit comments

Comments
 (0)