Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8bc930c

Browse filesBrowse files
committed
http2: fix endless loop when writing empty string
PR-URL: #18924 Fixes: #18169 Refs: #18673 Refs: https://github.com/nodejs/node/blob/v9.5.0/src/node_http2.cc#L1481-L1484 Refs: https://github.com/nodejs/node/blob/v9.5.0/lib/_http_outgoing.js#L659-L661 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent aa0fca9 commit 8bc930c
Copy full SHA for 8bc930c

File tree

Expand file treeCollapse file tree

1 file changed

+13
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-1
lines changed
Open diff view settings
Collapse file

‎src/node_http2.cc‎

Copy file name to clipboardExpand all lines: src/node_http2.cc
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,17 @@ ssize_t Http2Stream::Provider::Stream::OnRead(nghttp2_session* handle,
21922192

21932193
size_t amount = 0; // amount of data being sent in this data frame.
21942194

2195+
// Remove all empty chunks from the head of the queue.
2196+
// This is done here so that .write('', cb) is still a meaningful way to
2197+
// find out when the HTTP2 stream wants to consume data, and because the
2198+
// StreamBase API allows empty input chunks.
2199+
while (!stream->queue_.empty() && stream->queue_.front().buf.len == 0) {
2200+
WriteWrap* finished = stream->queue_.front().req_wrap;
2201+
stream->queue_.pop();
2202+
if (finished != nullptr)
2203+
finished->Done(0);
2204+
}
2205+
21952206
if (!stream->queue_.empty()) {
21962207
DEBUG_HTTP2SESSION2(session, "stream %d has pending outbound data", id);
21972208
amount = std::min(stream->available_outbound_length_, length);
@@ -2205,7 +2216,8 @@ ssize_t Http2Stream::Provider::Stream::OnRead(nghttp2_session* handle,
22052216
}
22062217
}
22072218

2208-
if (amount == 0 && stream->IsWritable() && stream->queue_.empty()) {
2219+
if (amount == 0 && stream->IsWritable()) {
2220+
CHECK(stream->queue_.empty());
22092221
DEBUG_HTTP2SESSION2(session, "deferring stream %d", id);
22102222
return NGHTTP2_ERR_DEFERRED;
22112223
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.