Skip to content

Commit

Permalink
http2: fix endless loop when writing empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Mar 5, 2018
1 parent aa0fca9 commit 8bc930c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,17 @@ ssize_t Http2Stream::Provider::Stream::OnRead(nghttp2_session* handle,

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

// Remove all empty chunks from the head of the queue.
// This is done here so that .write('', cb) is still a meaningful way to
// find out when the HTTP2 stream wants to consume data, and because the
// StreamBase API allows empty input chunks.
while (!stream->queue_.empty() && stream->queue_.front().buf.len == 0) {
WriteWrap* finished = stream->queue_.front().req_wrap;
stream->queue_.pop();
if (finished != nullptr)
finished->Done(0);
}

if (!stream->queue_.empty()) {
DEBUG_HTTP2SESSION2(session, "stream %d has pending outbound data", id);
amount = std::min(stream->available_outbound_length_, length);
Expand All @@ -2205,7 +2216,8 @@ ssize_t Http2Stream::Provider::Stream::OnRead(nghttp2_session* handle,
}
}

if (amount == 0 && stream->IsWritable() && stream->queue_.empty()) {
if (amount == 0 && stream->IsWritable()) {
CHECK(stream->queue_.empty());
DEBUG_HTTP2SESSION2(session, "deferring stream %d", id);
return NGHTTP2_ERR_DEFERRED;
}
Expand Down

0 comments on commit 8bc930c

Please sign in to comment.