chenBright commented on code in PR #3690:
URL: https://github.com/apache/brpc/pull/3690#discussion_r4441902614


##########
src/brpc/policy/http2_rpc_protocol.cpp:
##########
@@ -1301,15 +1402,38 @@ H2StreamContext::H2StreamContext(bool 
read_body_progressively)
 #endif
     , _stream_id(0)
     , _stream_ended(false)
+    , _remote_ended(false)
+    , _response_committed(false)
+    , _rst_received(false)
+    , _rst_error(H2_NO_ERROR)
     , _remote_window_left(0)
     , _deferred_window_update(0)
     , _correlation_id(INVALID_BTHREAD_ID.value)
     , _decoded_header_list_size(0)
-    , _rejected_error(H2_NO_ERROR) {
+    , _rejected_error(H2_NO_ERROR)
+    , _deferred_response_id(INVALID_BTHREAD_ID.value) {
     header().set_version(2, 0);
-#ifndef NDEBUG
     get_h2_bvars()->h2_stream_context_count << 1;
-#endif
+}
+
+int H2StreamContext::OnSocketFailed(bthread_id_t id, void* data, int 
error_code) {
+    butil::intrusive_ptr<H2StreamContext> sctx(
+        static_cast<H2StreamContext*>(data), false);
+    sctx->_deferred_response_id.store(
+        INVALID_BTHREAD_ID.value, butil::memory_order_release);
+    SocketUniquePtr sock(std::move(sctx->_deferred_response_sock));
+    if (sock != NULL) {
+        sock->ReleaseIdleFailRef();
+    }
+    if (error_code != 0 && sctx->_conn_ctx != NULL) {
+        H2StreamContext* removed =
+            sctx->_conn_ctx->RemoveStreamAndDeferWU(sctx->stream_id());
+        if (removed != NULL) {
+            removed->RemoveOneRefForStage2();

Review Comment:
   A nonzero error here does not necessarily mean the Socket has failed: 
`Socket::NotifyOnFailed()` also delivers `EAGAIN` when registration in the 
notification list fails, while the connection remains healthy. This branch can 
be reached when the concurrent stream limit is explicitly relaxed and many 
zero-window responses accumulate on the same connection. After the stream is 
removed here, `AppendAndDestroySelf()` still returns success and sends response 
headers without `END_STREAM`, but no `RST_STREAM` is sent. Subsequent window 
updates are also ignored because the stream cannot be found, leaving the call 
waiting for a timeout. Please distinguish registration failures from connection 
failures, explicitly terminate the stream or connection when registration 
fails, and add corresponding test cases.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to