From 59497fbec184dc0f4f6b9209e3812cc0b5aae113 Mon Sep 17 00:00:00 2001 From: Akshay K Date: Sun, 18 Jul 2021 15:02:07 -0400 Subject: [PATCH] http2: update checks for adding rst_stream to pending list http2: add checks to update the pending list if stream received in scope --- src/node_http2.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/node_http2.cc b/src/node_http2.cc index e18eda35e403b6..625f3adb3b9a9e 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -2196,15 +2196,24 @@ void Http2Stream::SubmitRstStream(const uint32_t code) { CHECK(!this->is_destroyed()); code_ = code; - // If RST_STREAM is submitted with the cancel code, don't force purge the - // currently sending data. Instead add it to the pending stream list to - // avoid prioritizing over other operations. + // If RST_STREAM frame is received and stream is not writable + // because it is busy reading data, don't try force purging it. + // Instead add the stream to pending stream list and process + // 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 (code_ == NGHTTP2_CANCEL) { + + // 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