Skip to content

Commit d48b91e

Browse files
kumarakrichardlau
authored andcommitted
http2: on receiving rst_stream with cancel code add it to pending list
PR-URL: #39423 Fixes: #38964 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 2ff671e commit d48b91e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/node_http2.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,25 @@ int Http2Stream::SubmitPriority(const Http2Priority& priority,
21182118
void Http2Stream::SubmitRstStream(const uint32_t code) {
21192119
CHECK(!this->is_destroyed());
21202120
code_ = code;
2121+
2122+
// If RST_STREAM frame is received and stream is not writable
2123+
// because it is busy reading data, don't try force purging it.
2124+
// Instead add the stream to pending stream list and process
2125+
// the pending data when it is safe to do so. This is to avoid
2126+
// double free error due to unwanted behavior of nghttp2.
2127+
// Ref:https://github.com/nodejs/node/issues/38964
2128+
2129+
// Add stream to the pending list if it is received with scope
2130+
// below in the stack. The pending list may not get processed
2131+
// if RST_STREAM received is not in scope and added to the list
2132+
// causing endpoint to hang.
2133+
if (session_->is_in_scope() &&
2134+
!is_writable() && is_reading()) {
2135+
session_->AddPendingRstStream(id_);
2136+
return;
2137+
}
2138+
2139+
21212140
// If possible, force a purge of any currently pending data here to make sure
21222141
// it is sent before closing the stream. If it returns non-zero then we need
21232142
// to wait until the current write finishes and try again to avoid nghttp2

0 commit comments

Comments
 (0)