Skip to content

Commit bfce0eb

Browse files
TrottMylesBorins
authored andcommitted
Revert "http2: streamline OnStreamRead streamline memory accounting"
This reverts commit 51ccf1b. Fixes: #31089 Backport-PR-URL: #34845 PR-URL: #34315 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Denys Otrishko <[email protected]>
1 parent 82af8ac commit bfce0eb

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/node_http2.cc

+9-10
Original file line numberDiff line numberDiff line change
@@ -1840,11 +1840,7 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
18401840

18411841
statistics_.data_received += nread;
18421842

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

1857-
// The data in stream_buf_ is already accounted for, add nread received
1858-
// bytes to session memory but remove the already processed
1859-
// stream_buf_offset_ bytes.
1860-
IncrementCurrentSessionMemory(nread - stream_buf_offset_);
1861-
18621853
buf = std::move(new_buf);
18631854
nread = buf.size();
18641855
stream_buf_offset_ = 0;
18651856
stream_buf_ab_.Reset();
1857+
1858+
// We have now fully processed the stream_buf_ input chunk (by moving the
1859+
// remaining part into buf, which will be accounted for below).
1860+
DecrementCurrentSessionMemory(stream_buf_.len);
18661861
}
18671862

1863+
// Shrink to the actual amount of used data.
1864+
buf.Resize(nread);
1865+
IncrementCurrentSessionMemory(nread);
1866+
18681867
// Remember the current buffer, so that OnDataChunkReceived knows the
18691868
// offset of a DATA frame's data into the socket read buffer.
18701869
stream_buf_ = uv_buf_init(buf.data(), nread);

0 commit comments

Comments
 (0)