-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: implement ref() and unref() on client sessions
Backport-PR-URL: #18050 PR-URL: #17620 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
- Loading branch information
1 parent
b8deb75
commit 1b7ce1e
Showing
4 changed files
with
159 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
// Flags: --expose-internals | ||
|
||
// Tests that calling unref() on Http2Session: | ||
// (1) Prevents it from keeping the process alive | ||
// (2) Doesn't crash | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const http2 = require('http2'); | ||
const makeDuplexPair = require('../common/duplexpair'); | ||
|
||
const server = http2.createServer(); | ||
const { clientSide, serverSide } = makeDuplexPair(); | ||
|
||
// 'session' event should be emitted 3 times: | ||
// - the vanilla client | ||
// - the destroyed client | ||
// - manual 'connection' event emission with generic Duplex stream | ||
server.on('session', common.mustCallAtLeast((session) => { | ||
session.unref(); | ||
}, 3)); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const port = server.address().port; | ||
|
||
// unref new client | ||
{ | ||
const client = http2.connect(`http://localhost:${port}`); | ||
client.unref(); | ||
} | ||
|
||
// unref destroyed client | ||
{ | ||
const client = http2.connect(`http://localhost:${port}`); | ||
client.destroy(); | ||
client.unref(); | ||
} | ||
|
||
// unref destroyed client | ||
{ | ||
const client = http2.connect(`http://localhost:${port}`, { | ||
createConnection: common.mustCall(() => clientSide) | ||
}); | ||
client.destroy(); | ||
client.unref(); | ||
} | ||
})); | ||
server.emit('connection', serverSide); | ||
server.unref(); | ||
|
||
setTimeout(common.mustNotCall(() => {}), 1000).unref(); |