Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2020-07-12 02:17:31 +0300
committerRich Trott <rtrott@gmail.com>2020-07-14 17:28:45 +0300
commite1b336ff551fa5e5ffb22bde4865e2c30c810cad (patch)
tree754ecbbb2e3bab7f7e9a1717aa6d882e25d73392 /src/node_http2.cc
parent9c11d5ce9df480b62ca1d5a0d90dd07fa55da98a (diff)
Revert "http2: streamline OnStreamRead streamline memory accounting"
This reverts commit 51ccf1b5e90540a11c33866da15d4a7f52d7fddb. Fixes: https://github.com/nodejs/node/issues/31089 PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'src/node_http2.cc')
-rw-r--r--src/node_http2.cc22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/node_http2.cc b/src/node_http2.cc
index de7a7f044e2..3227ae66a2d 100644
--- a/src/node_http2.cc
+++ b/src/node_http2.cc
@@ -1754,11 +1754,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
@@ -1769,20 +1765,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.
- // TODO(@jasnell): There are some cases where nread is < stream_buf_offset_
- // here but things still work. Those need to be investigated.
- // CHECK_GE(nread, stream_buf_offset_);
- 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(), static_cast<unsigned int>(nread));