diff --git a/src/node_http2.cc b/src/node_http2.cc index 20bb4728771def2..625f3adb3b9a9e9 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -2202,11 +2202,18 @@ void Http2Stream::SubmitRstStream(const uint32_t code) { // the pending data when it is safe to do so. This is to avoid // double free error due to unwanted behavior of nghttp2. // Ref:/~https://github.com/nodejs/node/issues/38964 - if (!is_writable() && is_reading()) { + + // Add stream to the pending list if it is received with scope + // below in the stack. The pending list may not get processed + // if RST_STREAM received is not in scope and added to the list + // causing endpoint to hang. + if (session_->is_in_scope() && + !is_writable() && is_reading()) { session_->AddPendingRstStream(id_); return; } + // If possible, force a purge of any currently pending data here to make sure // it is sent before closing the stream. If it returns non-zero then we need // to wait until the current write finishes and try again to avoid nghttp2