Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revert "http2: streamline OnStreamRead streamline memory accounting"
This reverts commit 51ccf1b.

Fixes: #31089

Backport-PR-URL: #34845
PR-URL: #34315
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
  • Loading branch information
Trott authored and MylesBorins committed Nov 16, 2020
1 parent 82af8ac commit bfce0eb
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/node_http2.cc
Expand Up @@ -1840,11 +1840,7 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {

statistics_.data_received += nread;

if (LIKELY(stream_buf_offset_ == 0)) {
// Shrink to the actual amount of used data.
buf.Resize(nread);
IncrementCurrentSessionMemory(nread);
} else {
if (UNLIKELY(stream_buf_offset_ > 0)) {
// This is a very unlikely case, and should only happen if the ReadStart()
// call in OnStreamAfterWrite() immediately provides data. If that does
// happen, we concatenate the data we received with the already-stored
Expand All @@ -1854,17 +1850,20 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
memcpy(new_buf.data(), stream_buf_.base + stream_buf_offset_, pending_len);
memcpy(new_buf.data() + pending_len, buf.data(), nread);

// The data in stream_buf_ is already accounted for, add nread received
// bytes to session memory but remove the already processed
// stream_buf_offset_ bytes.
IncrementCurrentSessionMemory(nread - stream_buf_offset_);

buf = std::move(new_buf);
nread = buf.size();
stream_buf_offset_ = 0;
stream_buf_ab_.Reset();

// We have now fully processed the stream_buf_ input chunk (by moving the
// remaining part into buf, which will be accounted for below).
DecrementCurrentSessionMemory(stream_buf_.len);
}

// Shrink to the actual amount of used data.
buf.Resize(nread);
IncrementCurrentSessionMemory(nread);

// Remember the current buffer, so that OnDataChunkReceived knows the
// offset of a DATA frame's data into the socket read buffer.
stream_buf_ = uv_buf_init(buf.data(), nread);
Expand Down

0 comments on commit bfce0eb

Please sign in to comment.