This is an automated email from the ASF dual-hosted git repository.
chenBright pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new b3ab44b0 Fix StreamCreate failure handling (#3357)
b3ab44b0 is described below
commit b3ab44b072b5ec7e462e2b9aa0deeb2bd771604e
Author: ljcjclljc <[email protected]>
AuthorDate: Sat Jul 11 07:54:08 2026 +0800
Fix StreamCreate failure handling (#3357)
* Fix StreamCreate failure handling
* Add ScopedStream guard to stream test
* Move stream regression test into streaming UT
* Fix StreamCreate failure handling
* Add ScopedStream guard to stream test
* Move stream regression test into streaming UT
---
src/brpc/stream.cpp | 5 ++++-
test/brpc_streaming_rpc_unittest.cpp | 12 ++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/brpc/stream.cpp b/src/brpc/stream.cpp
index a2a106a8..01504d3d 100644
--- a/src/brpc/stream.cpp
+++ b/src/brpc/stream.cpp
@@ -837,7 +837,10 @@ int StreamCreate(StreamId *request_stream, Controller
&cntl,
return -1;
}
StreamIds request_streams;
- StreamCreate(request_streams, 1, cntl, options);
+ const int rc = StreamCreate(request_streams, 1, cntl, options);
+ if (rc != 0) {
+ return rc;
+ }
*request_stream = request_streams[0];
return 0;
}
diff --git a/test/brpc_streaming_rpc_unittest.cpp
b/test/brpc_streaming_rpc_unittest.cpp
index 6a3b7b9e..fc82fcde 100644
--- a/test/brpc_streaming_rpc_unittest.cpp
+++ b/test/brpc_streaming_rpc_unittest.cpp
@@ -888,3 +888,15 @@ TEST_F(StreamingRpcTest,
segment_stream_data_automatically) {
ASSERT_EQ(N, handler._expected_next_value);
GFLAGS_NAMESPACE::SetCommandLineOption("stream_write_max_segment_size",
"536870912");
}
+
+TEST_F(StreamingRpcTest,
create_request_stream_twice_on_same_controller_returns_error) {
+ brpc::Controller cntl;
+
+ brpc::StreamId first_stream = brpc::INVALID_STREAM_ID;
+ ASSERT_EQ(0, brpc::StreamCreate(&first_stream, cntl, NULL));
+ brpc::ScopedStream stream_guard(first_stream);
+
+ brpc::StreamId second_stream = brpc::INVALID_STREAM_ID;
+ ASSERT_EQ(-1, brpc::StreamCreate(&second_stream, cntl, NULL));
+ ASSERT_EQ(brpc::INVALID_STREAM_ID, second_stream);
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]