diff --git a/packages/node-http-handler/package.json b/packages/node-http-handler/package.json index 4d0ae5c0f83d..93d406f8efdb 100644 --- a/packages/node-http-handler/package.json +++ b/packages/node-http-handler/package.json @@ -36,12 +36,6 @@ "typedoc": "0.19.2", "typescript": "~4.6.2" }, - "jest": { - "coveragePathIgnorePatterns": [ - "/node_modules/", - "/*.mock.ts" - ] - }, "engines": { "node": ">= 12.0.0" }, diff --git a/packages/node-http-handler/src/node-http2-handler.spec.ts b/packages/node-http-handler/src/node-http2-handler.spec.ts index e2ab24446a4d..60626387d028 100644 --- a/packages/node-http-handler/src/node-http2-handler.spec.ts +++ b/packages/node-http-handler/src/node-http2-handler.spec.ts @@ -239,21 +239,22 @@ describe(NodeHttp2Handler.name, () => { expectSessionCreatedAndUnreffed(createdSessions[3]); }); - it("handles connections destroyed by servers", async () => { - const port3 = port + 2; - const mockH2Server3 = createMockHttp2Server().listen(port3); + it.each([ + ["destroy", port + 2], + ["close", port + 3], + ])("handles servers calling connections %s", async (func, port) => { + const mockH2Server4 = createMockHttp2Server().listen(port); let establishedConnections = 0; let numRequests = 0; - mockH2Server3.on("stream", (request: Http2Stream) => { - // transmit goaway frame and then shut down the connection. + mockH2Server4.on("stream", (request: Http2Stream) => { numRequests += 1; - request.session.destroy(); + request.session[func](); }); - mockH2Server3.on("connection", () => { + mockH2Server4.on("connection", () => { establishedConnections += 1; }); - const req = new HttpRequest({ ...getMockReqOptions(), port: port3 }); + const req = new HttpRequest({ ...getMockReqOptions(), port }); expect(establishedConnections).toBe(0); expect(numRequests).toBe(0); await rejects( @@ -277,7 +278,7 @@ describe(NodeHttp2Handler.name, () => { ); expect(establishedConnections).toBe(3); expect(numRequests).toBe(3); - mockH2Server3.close(); + mockH2Server4.close(); // Not keeping node alive expect(createdSessions).toHaveLength(3); diff --git a/packages/node-http-handler/src/node-http2-handler.ts b/packages/node-http-handler/src/node-http2-handler.ts index 4fa4a36ff6b4..155f90a319d7 100644 --- a/packages/node-http-handler/src/node-http2-handler.ts +++ b/packages/node-http-handler/src/node-http2-handler.ts @@ -190,6 +190,8 @@ export class NodeHttp2Handler implements HttpHandler { newSession.on("error", destroySessionCb); newSession.on("frameError", destroySessionCb); + newSession.on("close", () => this.deleteSessionFromCache(authority, newSession)); + if (this.config?.sessionTimeout) { newSession.setTimeout(this.config.sessionTimeout, destroySessionCb); }