-
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: only schedule write when necessary
Introduce an `Http2Scope` class that, when it goes out of scope, checks whether a write to the network is desired by nghttp2. If that is the case, schedule a write using `SetImmediate()` rather than a custom per-session libuv handle. Backport-PR-URL: #18050 Backport-PR-URL: #20456 PR-URL: #17183 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
- Loading branch information
1 parent
38cfb70
commit 8431b42
Showing
3 changed files
with
114 additions
and
41 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
32 changes: 32 additions & 0 deletions
32
test/parallel/test-http2-session-gc-while-write-scheduled.js
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,32 @@ | ||
// Flags: --expose-gc | ||
|
||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const http2 = require('http2'); | ||
const makeDuplexPair = require('../common/duplexpair'); | ||
|
||
// This tests that running garbage collection while an Http2Session has | ||
// a write *scheduled*, it will survive that garbage collection. | ||
|
||
{ | ||
// This creates a session and schedules a write (for the settings frame). | ||
let client = http2.connect('http://localhost:80', { | ||
createConnection: common.mustCall(() => makeDuplexPair().clientSide) | ||
}); | ||
|
||
// First, wait for any nextTicks() and their responses | ||
// from the `connect()` call to run. | ||
tick(10, () => { | ||
// This schedules a write. | ||
client.settings(http2.getDefaultSettings()); | ||
client = null; | ||
global.gc(); | ||
}); | ||
} | ||
|
||
function tick(n, cb) { | ||
if (n--) setImmediate(tick, n, cb); | ||
else cb(); | ||
} |