File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -2150,6 +2150,23 @@ int Http2Stream::SubmitPriority(nghttp2_priority_spec* prispec,
2150
2150
void Http2Stream::SubmitRstStream (const uint32_t code) {
2151
2151
CHECK (!this ->IsDestroyed ());
2152
2152
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 () && IsReading ()) {
2166
+ session_->AddPendingRstStream (id_);
2167
+ return ;
2168
+ }
2169
+
2153
2170
// If possible, force a purge of any currently pending data here to make sure
2154
2171
// it is sent before closing the stream. If it returns non-zero then we need
2155
2172
// to wait until the current write finishes and try again to avoid nghttp2
Original file line number Diff line number Diff line change @@ -764,6 +764,22 @@ class Http2Session : public AsyncWrap,
764
764
return (flags_ & SESSION_STATE_CLOSED) || session_ == nullptr ;
765
765
}
766
766
767
+
768
+ // The changes are backported and exposes APIs to check the
769
+ // status flag of `Http2Session`
770
+ #define IS_FLAG (name, flag ) \
771
+ bool is_##name() const { return flags_ & flag; }
772
+
773
+ IS_FLAG (in_scope, SESSION_STATE_HAS_SCOPE)
774
+ IS_FLAG (write_scheduled, SESSION_STATE_WRITE_SCHEDULED)
775
+ IS_FLAG (closing, SESSION_STATE_CLOSING)
776
+ IS_FLAG (sending, SESSION_STATE_SENDING)
777
+ IS_FLAG (write_in_progress, SESSION_STATE_WRITE_IN_PROGRESS)
778
+ IS_FLAG (reading_stopped, SESSION_STATE_READING_STOPPED)
779
+ IS_FLAG (receive_paused, SESSION_STATE_NGHTTP2_RECV_PAUSED)
780
+
781
+ #undef IS_FLAG
782
+
767
783
// Schedule a write if nghttp2 indicates it wants to write to the socket.
768
784
void MaybeScheduleWrite ();
769
785
You can’t perform that action at this time.
0 commit comments