diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-05-26 18:48:47 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-05-29 13:26:38 +0300 |
commit | b84b4d8c7dc957dd630a66ee372c6f29e173e98d (patch) | |
tree | 4d541fd47add0dbf1bb9599554b21cb35297d715 /src/node_http2.cc | |
parent | eb4c1d5663ff7089badfeaf37dbe246df60607e9 (diff) |
http2: fix tracking received data for maxSessionMemory
Track received data correctly. Specifically, for the buffer that
is used for receiving data, we previously would try to increment
the current memory usage by its length, and later decrement it
by that, but in the meantime the buffer had been turned over to V8
and its length reset to zero. This gave the impression that more and
more memory was consumed by the HTTP/2 session when it was in fact not.
Fixes: https://github.com/nodejs/node/issues/27416
Refs: https://github.com/nodejs/node/pull/26207
PR-URL: https://github.com/nodejs/node/pull/27914
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_http2.cc')
-rw-r--r-- | src/node_http2.cc | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/node_http2.cc b/src/node_http2.cc index d9b886284dd..3a7591f31af 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -1782,11 +1782,13 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) { // Shrink to the actual amount of used data. buf.Resize(nread); - IncrementCurrentSessionMemory(buf.size()); + IncrementCurrentSessionMemory(nread); OnScopeLeave on_scope_leave([&]() { // Once finished handling this write, reset the stream buffer. // The memory has either been free()d or was handed over to V8. - DecrementCurrentSessionMemory(buf.size()); + // We use `nread` instead of `buf.size()` here, because the buffer is + // cleared as part of the `.ToArrayBuffer()` call below. + DecrementCurrentSessionMemory(nread); stream_buf_ab_ = Local<ArrayBuffer>(); stream_buf_ = uv_buf_init(nullptr, 0); }); |