diff options
author | Rafael Silva <rafael.nunu@hotmail.com> | 2022-01-28 19:28:46 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-28 19:28:46 +0300 |
commit | f98a785dab1a7f520b0cc8e102771b6c5c24a36e (patch) | |
tree | 92376c5181a0989b9d633f723c5307c14ddfc575 /src/node_http2.cc | |
parent | 5a61ca63b9ef33cd814c703051bc777a6771f205 (diff) |
http2: fix memory leak on nghttp2 hd threshold
PR-URL: https://github.com/nodejs/node/pull/41502
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Diffstat (limited to 'src/node_http2.cc')
-rw-r--r-- | src/node_http2.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/node_http2.cc b/src/node_http2.cc index f5a1db0d022..eb33da6eae7 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -1009,6 +1009,21 @@ int Http2Session::OnInvalidFrame(nghttp2_session* handle, return 0; } +// Remove the headers reference. +// Implicitly calls nghttp2_rcbuf_decref +void Http2Session::DecrefHeaders(const nghttp2_frame* frame) { + int32_t id = GetFrameID(frame); + BaseObjectPtr<Http2Stream> stream = FindStream(id); + + if (stream && !stream->is_destroyed() && stream->headers_count() > 0) { + Debug(this, "freeing headers for stream %d", id); + stream->ClearHeaders(); + CHECK_EQ(stream->headers_count(), 0); + DecrementCurrentSessionMemory(stream->current_headers_length_); + stream->current_headers_length_ = 0; + } +} + // If nghttp2 is unable to send a queued up frame, it will call this callback // to let us know. If the failure occurred because we are in the process of // closing down the session or stream, we go ahead and ignore it. We don't @@ -1029,6 +1044,11 @@ int Http2Session::OnFrameNotSent(nghttp2_session* handle, error_code == NGHTTP2_ERR_STREAM_CLOSED || error_code == NGHTTP2_ERR_STREAM_CLOSING || session->js_fields_->frame_error_listener_count == 0) { + // Nghttp2 contains header limit of 65536. When this value is exceeded the + // pipeline is stopped and we should remove the current headers reference + // to destroy the session completely. + // Further information see: https://github.com/nodejs/node/issues/35233 + session->DecrefHeaders(frame); return 0; } |