@@ -1009,6 +1009,21 @@ int Http2Session::OnInvalidFrame(nghttp2_session* handle,
10091009 return 0 ;
10101010}
10111011
1012+ // Remove the headers reference.
1013+ // Implicitly calls nghttp2_rcbuf_decref
1014+ void Http2Session::DecrefHeaders (const nghttp2_frame* frame) {
1015+ int32_t id = GetFrameID (frame);
1016+ BaseObjectPtr<Http2Stream> stream = FindStream (id);
1017+
1018+ if (stream && !stream->is_destroyed () && stream->headers_count () > 0 ) {
1019+ Debug (this , " freeing headers for stream %d" , id);
1020+ stream->ClearHeaders ();
1021+ CHECK_EQ (stream->headers_count (), 0 );
1022+ DecrementCurrentSessionMemory (stream->current_headers_length_ );
1023+ stream->current_headers_length_ = 0 ;
1024+ }
1025+ }
1026+
10121027// If nghttp2 is unable to send a queued up frame, it will call this callback
10131028// to let us know. If the failure occurred because we are in the process of
10141029// closing down the session or stream, we go ahead and ignore it. We don't
@@ -1029,6 +1044,11 @@ int Http2Session::OnFrameNotSent(nghttp2_session* handle,
10291044 error_code == NGHTTP2_ERR_STREAM_CLOSED ||
10301045 error_code == NGHTTP2_ERR_STREAM_CLOSING ||
10311046 session->js_fields_ ->frame_error_listener_count == 0 ) {
1047+ // Nghttp2 contains header limit of 65536. When this value is exceeded the
1048+ // pipeline is stopped and we should remove the current headers reference
1049+ // to destroy the session completely.
1050+ // Further information see: https://github.com/nodejs/node/issues/35233
1051+ session->DecrefHeaders (frame);
10321052 return 0 ;
10331053 }
10341054
0 commit comments