Skip to content

Commit 2b6fd9a

Browse files
kaijchenliaoxin01
andcommitted
Fix: set connected before send stream data
Co-authored-by: Xin Liao <[email protected]>
1 parent 552bd30 commit 2b6fd9a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/brpc/policy/baidu_rpc_protocol.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ void SendRpcResponse(int64_t correlation_id,
247247
// Send rpc response over stream even if server side failed to create
248248
// stream for some reason.
249249
if(cntl->has_remote_stream()){
250+
// In certain cases, if the server-side stream is actively closing the stream.
251+
// The client-side cannot receive on_closed message due to connectted is not set.
252+
// We should set connected before send stream data.
253+
if (stream_ptr) {
254+
// Now it's ok the mark this server-side stream as connectted as all the
255+
// written user data would follower the RPC response.
256+
((Stream*)stream_ptr->conn())->SetConnected();
257+
}
250258
// Send the response over stream to notify that this stream connection
251259
// is successfully built.
252260
// Response_stream can be INVALID_STREAM_ID when error occurs.
@@ -262,12 +270,6 @@ void SendRpcResponse(int64_t correlation_id,
262270
}
263271
return;
264272
}
265-
266-
if(stream_ptr) {
267-
// Now it's ok the mark this server-side stream as connected as all the
268-
// written user data would follower the RPC response.
269-
((Stream*)stream_ptr->conn())->SetConnected();
270-
}
271273
} else{
272274
// Have the risk of unlimited pending responses, in which case, tell
273275
// users to set max_concurrency.

0 commit comments

Comments
 (0)