Skip to content

Commit c528661

Browse files
authored
fix(node-http-handler): handle close event in H2 from server side (#3619)
1 parent cf420b3 commit c528661

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

packages/node-http-handler/package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@
3636
"typedoc": "0.19.2",
3737
"typescript": "~4.6.2"
3838
},
39-
"jest": {
40-
"coveragePathIgnorePatterns": [
41-
"/node_modules/",
42-
"<rootDir>/*.mock.ts"
43-
]
44-
},
4539
"engines": {
4640
"node": ">= 12.0.0"
4741
},

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,21 +239,22 @@ describe(NodeHttp2Handler.name, () => {
239239
expectSessionCreatedAndUnreffed(createdSessions[3]);
240240
});
241241

242-
it("handles connections destroyed by servers", async () => {
243-
const port3 = port + 2;
244-
const mockH2Server3 = createMockHttp2Server().listen(port3);
242+
it.each([
243+
["destroy", port + 2],
244+
["close", port + 3],
245+
])("handles servers calling connections %s", async (func, port) => {
246+
const mockH2Server4 = createMockHttp2Server().listen(port);
245247
let establishedConnections = 0;
246248
let numRequests = 0;
247249

248-
mockH2Server3.on("stream", (request: Http2Stream) => {
249-
// transmit goaway frame and then shut down the connection.
250+
mockH2Server4.on("stream", (request: Http2Stream) => {
250251
numRequests += 1;
251-
request.session.destroy();
252+
request.session[func]();
252253
});
253-
mockH2Server3.on("connection", () => {
254+
mockH2Server4.on("connection", () => {
254255
establishedConnections += 1;
255256
});
256-
const req = new HttpRequest({ ...getMockReqOptions(), port: port3 });
257+
const req = new HttpRequest({ ...getMockReqOptions(), port });
257258
expect(establishedConnections).toBe(0);
258259
expect(numRequests).toBe(0);
259260
await rejects(
@@ -277,7 +278,7 @@ describe(NodeHttp2Handler.name, () => {
277278
);
278279
expect(establishedConnections).toBe(3);
279280
expect(numRequests).toBe(3);
280-
mockH2Server3.close();
281+
mockH2Server4.close();
281282

282283
// Not keeping node alive
283284
expect(createdSessions).toHaveLength(3);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ export class NodeHttp2Handler implements HttpHandler {
190190
newSession.on("error", destroySessionCb);
191191
newSession.on("frameError", destroySessionCb);
192192

193+
newSession.on("close", () => this.deleteSessionFromCache(authority, newSession));
194+
193195
if (this.config?.sessionTimeout) {
194196
newSession.setTimeout(this.config.sessionTimeout, destroySessionCb);
195197
}

0 commit comments

Comments
 (0)