File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2196,15 +2196,24 @@ void Http2Stream::SubmitRstStream(const uint32_t code) {
21962196 CHECK (!this ->is_destroyed ());
21972197 code_ = code;
21982198
2199- // If RST_STREAM is submitted with the cancel code, don't force purge the
2200- // currently sending data. Instead add it to the pending stream list to
2201- // avoid prioritizing over other operations.
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.
22022204 // Ref:https://github.com/nodejs/node/issues/38964
2203- if (code_ == NGHTTP2_CANCEL) {
2205+
2206+ // Add stream to the pending list if it is received with scope
2207+ // below in the stack. The pending list may not get processed
2208+ // if RST_STREAM received is not in scope and added to the list
2209+ // causing endpoint to hang.
2210+ if (session_->is_in_scope () &&
2211+ !is_writable () && is_reading ()) {
22042212 session_->AddPendingRstStream (id_);
22052213 return ;
22062214 }
22072215
2216+
22082217 // If possible, force a purge of any currently pending data here to make sure
22092218 // it is sent before closing the stream. If it returns non-zero then we need
22102219 // to wait until the current write finishes and try again to avoid nghttp2
You can’t perform that action at this time.
0 commit comments