Skip to content

Commit 9d950a0

Browse files
kumarakBethGriggs
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 ae69656 commit 9d950a0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/node_http2.cc

+19
Original file line numberDiff line numberDiff line change
@@ -2195,6 +2195,25 @@ int Http2Stream::SubmitPriority(const Http2Priority& priority,
21952195
void Http2Stream::SubmitRstStream(const uint32_t code) {
21962196
CHECK(!this->is_destroyed());
21972197
code_ = code;
2198+
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
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()) {
2212+
session_->AddPendingRstStream(id_);
2213+
return;
2214+
}
2215+
2216+
21982217
// If possible, force a purge of any currently pending data here to make sure
21992218
// it is sent before closing the stream. If it returns non-zero then we need
22002219
// to wait until the current write finishes and try again to avoid nghttp2

0 commit comments

Comments
 (0)