-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: refactor ping + settings object lifetime management
Have clearer ownership relations between the `Http2Ping`, `Http2Settings` and `Http2Session` objects. Ping and Settings objects are now owned by the `Http2Session` instance, and deleted along with it, so neither type of object refers to the session after it is gone. In the case of `Http2Ping`s, that deletion is slightly delayed, so we explicitly reset its `session_` property. Fixes: #28088 PR-URL: #28150 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
- Loading branch information
Showing
5 changed files
with
111 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const http2 = require('http2'); | ||
const v8 = require('v8'); | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/28088: | ||
// Verify that Http2Settings and Http2Ping objects don't reference the session | ||
// after it is destroyed, either because they are detached from it or have been | ||
// destroyed themselves. | ||
|
||
for (const variant of ['ping', 'settings']) { | ||
const server = http2.createServer(); | ||
server.on('session', common.mustCall((session) => { | ||
if (variant === 'ping') { | ||
session.ping(common.expectsError({ | ||
code: 'ERR_HTTP2_PING_CANCEL' | ||
})); | ||
} else { | ||
session.settings(undefined, common.mustNotCall()); | ||
} | ||
|
||
session.on('close', common.mustCall(() => { | ||
v8.getHeapSnapshot().resume(); | ||
server.close(); | ||
})); | ||
session.destroy(); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
http2.connect(`http://localhost:${server.address().port}`, | ||
common.mustCall()); | ||
})); | ||
} |