diff --git a/src/node_http2.cc b/src/node_http2.cc index 0d0faaaa752c4a..cf99e21928d89b 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -605,6 +605,12 @@ Http2Session::Http2Session(Http2State* http2_state, Http2Session::~Http2Session() { CHECK(!is_in_scope()); Debug(this, "freeing nghttp2 session"); + // Ensure that all `Http2Stream` instances and the memory they hold + // on to are destroyed before the nghttp2 session is. + for (const auto& [id, stream] : streams_) { + stream->Detach(); + } + streams_.clear(); // Explicitly reset session_ so the subsequent // current_nghttp2_memory_ check passes. session_.reset();