Skip to content
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

http2: backport changes to v9.x-staging #18050

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1724a4e
src: add optional keep-alive object to SetImmediate
addaleax Nov 21, 2017
df31133
http2: don't call into JS from GC
addaleax Nov 21, 2017
8c28e30
http2: only schedule write when necessary
addaleax Nov 21, 2017
504ee24
http2: be sure to destroy the Http2Stream
jasnell Nov 27, 2017
ac89b78
http2: cleanup Http2Stream/Http2Session destroy
jasnell Dec 12, 2017
7ab5c62
http2: remove redundant write indirection
addaleax Dec 17, 2017
66be8e5
http2: refactor outgoing write mechanism
addaleax Dec 17, 2017
293c2f9
http2: convert Http2Settings to an AsyncWrap
jasnell Dec 18, 2017
08478c1
http2: fix compiling with `--debug-http2`
addaleax Dec 25, 2017
b61c3fc
http2: keep session objects alive during Http2Scope
addaleax Dec 25, 2017
afa4a7c
http2: implement ref() and unref() on client sessions
kjin Dec 11, 2017
8d8dfea
http2: remove duplicate words in comments
tniessen Jan 1, 2018
d968c02
http2: perf_hooks integration
jasnell Dec 20, 2017
bf7eed3
http2: strictly limit number on concurrent streams
jasnell Nov 21, 2017
8df5d02
http2: add altsvc support
jasnell Dec 29, 2017
ae4e308
tls: set servername on client side too
jasnell Jan 1, 2018
7d6aa20
http2: add initial support for originSet
jasnell Jan 1, 2018
760f678
http2: add aligned padding strategy
jasnell Jan 1, 2018
06ed513
http2: properly handle already closed stream error
jasnell Jan 2, 2018
e929bd0
doc: add docs for common/http2.js utility
jasnell Jan 2, 2018
c1c4a6c
src: silence http2 -Wunused-result warnings
cjihrig Jan 2, 2018
adbc38a
http2: implement maxSessionMemory
jasnell Jan 3, 2018
51dc318
http2: verify that a dependency cycle may exist
jasnell Jan 3, 2018
d1e75eb
doc: grammar fixes in http2.md
Trott Jan 4, 2018
cd6fcf3
http2: verify flood error and unsolicited frames
jasnell Jan 3, 2018
526cf84
doc: correct spelling
sreepurnajasti Dec 29, 2017
d7dd941
perf_hooks: fix scheduling regression
apapirovski Jan 9, 2018
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
Prev Previous commit
Next Next commit
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

PR-URL: #16766
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Sebastiaan Deckers <sebdeckers83@gmail.com>
  • Loading branch information
jasnell authored and MylesBorins committed Jan 9, 2018
commit bf7eed367673d31dac66cd148f26a69a1d1c8709
19 changes: 18 additions & 1 deletion src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,16 @@ inline Http2Stream* Http2Session::FindStream(int32_t id) {
return s != streams_.end() ? s->second : nullptr;
}

inline bool Http2Session::CanAddStream() {
uint32_t maxConcurrentStreams =
nghttp2_session_get_local_settings(
session_, NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS);
size_t maxSize =
std::min(streams_.max_size(), static_cast<size_t>(maxConcurrentStreams));
// We can add a new stream so long as we are less than the current
// maximum on concurrent streams
return streams_.size() < maxSize;
}

inline void Http2Session::AddStream(Http2Stream* stream) {
CHECK_GE(++statistics_.stream_count, 0);
Expand Down Expand Up @@ -765,7 +775,14 @@ inline int Http2Session::OnBeginHeadersCallback(nghttp2_session* handle,

Http2Stream* stream = session->FindStream(id);
if (stream == nullptr) {
new Http2Stream(session, id, frame->headers.cat);
if (session->CanAddStream()) {
new Http2Stream(session, id, frame->headers.cat);
} else {
// Too many concurrent streams being opened
nghttp2_submit_rst_stream(**session, NGHTTP2_FLAG_NONE, id,
NGHTTP2_ENHANCE_YOUR_CALM);
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
}
} else {
// If the stream has already been destroyed, ignore.
if (stream->IsDestroyed())
Expand Down
2 changes: 2 additions & 0 deletions src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,8 @@ class Http2Session : public AsyncWrap {
// Returns pointer to the stream, or nullptr if stream does not exist
inline Http2Stream* FindStream(int32_t id);

inline bool CanAddStream();

// Adds a stream instance to this session
inline void AddStream(Http2Stream* stream);

Expand Down
60 changes: 60 additions & 0 deletions test/parallel/test-http2-too-many-streams.js
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());
}
}));
}));