Skip to content

fix(node-http-handler): handle close event in H2 from server side #3619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions packages/node-http-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@
"typedoc": "0.19.2",
"typescript": "~4.6.2"
},
"jest": {
"coveragePathIgnorePatterns": [
"/node_modules/",
"<rootDir>/*.mock.ts"
]
},
"engines": {
"node": ">= 12.0.0"
},
Expand Down
19 changes: 10 additions & 9 deletions packages/node-http-handler/src/node-http2-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions packages/node-http-handler/src/node-http2-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down