Skip to content

Commit 59497fb

Browse files
committed
http2: update checks for adding rst_stream to pending list
http2: add checks to update the pending list if stream received in scope
1 parent f3ea45e commit 59497fb

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/node_http2.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)