File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -2150,6 +2150,25 @@ int Http2Stream::SubmitPriority(nghttp2_priority_spec* prispec,
21502150void Http2Stream::SubmitRstStream (const uint32_t code) {
21512151 CHECK (!this ->IsDestroyed ());
21522152 code_ = code;
2153+
2154+ // If RST_STREAM frame is received and stream is not writable
2155+ // because it is busy reading data, don't try force purging it.
2156+ // Instead add the stream to pending stream list and process
2157+ // the pending data when it is safe to do so. This is to avoid
2158+ // double free error due to unwanted behavior of nghttp2.
2159+ // Ref:https://github.com/nodejs/node/issues/38964
2160+
2161+ // Add stream to the pending list if it is received with scope
2162+ // below in the stack. The pending list may not get processed
2163+ // if RST_STREAM received is not in scope and added to the list
2164+ // causing endpoint to hang.
2165+ if (session_->is_in_scope () &&
2166+ !is_writable () && is_reading ()) {
2167+ session_->AddPendingRstStream (id_);
2168+ return ;
2169+ }
2170+
2171+
21532172 // If possible, force a purge of any currently pending data here to make sure
21542173 // it is sent before closing the stream. If it returns non-zero then we need
21552174 // 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