-
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: strictly limit number on concurrent streams
Strictly limit the number of concurrent streams based on the current setting of the MAX_CONCURRENT_STREAMS setting Backport-PR-URL: #18050 Backport-PR-URL: #20456 PR-URL: #16766 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Sebastiaan Deckers <[email protected]>
- Loading branch information
1 parent
9a4bac2
commit c915bc5
Showing
3 changed files
with
80 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const Countdown = require('../common/countdown'); | ||
const http2 = require('http2'); | ||
const assert = require('assert'); | ||
|
||
// Test that the maxConcurrentStreams setting is strictly enforced | ||
|
||
const server = http2.createServer({ settings: { maxConcurrentStreams: 1 } }); | ||
|
||
let c = 0; | ||
|
||
server.on('stream', common.mustCall((stream) => { | ||
// Because we only allow one open stream at a time, | ||
// c should never be greater than 1. | ||
assert.strictEqual(++c, 1); | ||
stream.respond(); | ||
// Force some asynchronos stuff. | ||
setImmediate(() => { | ||
stream.end('ok'); | ||
assert.strictEqual(--c, 0); | ||
}); | ||
}, 3)); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const client = http2.connect(`http://localhost:${server.address().port}`); | ||
|
||
const countdown = new Countdown(3, common.mustCall(() => { | ||
server.close(); | ||
client.destroy(); | ||
})); | ||
|
||
client.on('remoteSettings', common.mustCall(() => { | ||
assert.strictEqual(client.remoteSettings.maxConcurrentStreams, 1); | ||
|
||
{ | ||
const req = client.request(); | ||
req.resume(); | ||
req.on('close', () => { | ||
countdown.dec(); | ||
|
||
setImmediate(() => { | ||
const req = client.request(); | ||
req.resume(); | ||
req.on('close', () => countdown.dec()); | ||
}); | ||
}); | ||
} | ||
|
||
{ | ||
const req = client.request(); | ||
req.resume(); | ||
req.on('close', () => countdown.dec()); | ||
} | ||
})); | ||
})); |