@@ -2196,21 +2196,21 @@ void Http2Stream::SubmitRstStream(const uint32_t code) {
21962196 CHECK (!this ->is_destroyed ());
21972197 code_ = code;
21982198
2199- // If RST_STREAM frame is received and stream is not writable
2200- // because it is busy reading data, don't try force purging it.
2201- // Instead add the stream to pending stream list and process
2202- // the pending data when it is safe to do so. This is to avoid
2203- // double free error due to unwanted behavior of nghttp2.
2204- // Ref:https://github.com/nodejs/node/issues/38964
2205-
2206- // Add stream to the pending list if it is received with scope
2199+ auto is_stream_cancel = [](const uint32_t code) {
2200+ return code == NGHTTP2_CANCEL;
2201+ };
2202+
2203+ // If RST_STREAM frame is received with error code NGHTTP2_CANCEL,
2204+ // add it to the pending list and don't force purge the data. It is
2205+ // to avoids the double free error due to unwanted behavior of nghttp2.
2206+
2207+ // Add stream to the pending list only if it is received with scope
22072208 // below in the stack. The pending list may not get processed
22082209 // if RST_STREAM received is not in scope and added to the list
22092210 // causing endpoint to hang.
2210- if (session_->is_in_scope () &&
2211- !is_writable () && is_reading ()) {
2212- session_->AddPendingRstStream (id_);
2213- return ;
2211+ if (session_->is_in_scope () && is_stream_cancel (code)) {
2212+ session_->AddPendingRstStream (id_);
2213+ return ;
22142214 }
22152215
22162216
0 commit comments