Skip to content

Commit

Permalink
Fix: set connected before send stream data
Browse files Browse the repository at this point in the history
Co-authored-by: Xin Liao <liaoxinbit@126.com>
  • Loading branch information
kaijchen and liaoxin01 committed Feb 4, 2024
1 parent 552bd30 commit 2b6fd9a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/brpc/policy/baidu_rpc_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ void SendRpcResponse(int64_t correlation_id,
// Send rpc response over stream even if server side failed to create
// stream for some reason.
if(cntl->has_remote_stream()){
// In certain cases, if the server-side stream is actively closing the stream.
// The client-side cannot receive on_closed message due to connectted is not set.
// We should set connected before send stream data.
if (stream_ptr) {
// Now it's ok the mark this server-side stream as connectted as all the
// written user data would follower the RPC response.
((Stream*)stream_ptr->conn())->SetConnected();
}
// Send the response over stream to notify that this stream connection
// is successfully built.
// Response_stream can be INVALID_STREAM_ID when error occurs.
Expand All @@ -262,12 +270,6 @@ void SendRpcResponse(int64_t correlation_id,
}
return;
}

if(stream_ptr) {
// Now it's ok the mark this server-side stream as connected as all the
// written user data would follower the RPC response.
((Stream*)stream_ptr->conn())->SetConnected();
}
} else{
// Have the risk of unlimited pending responses, in which case, tell
// users to set max_concurrency.
Expand Down

0 comments on commit 2b6fd9a

Please sign in to comment.