From 1bf809d026108d7904fc6f2b16879f6593c04d4e Mon Sep 17 00:00:00 2001 From: ljccjlljc <939159710@qq.com> Date: Thu, 25 Jun 2026 00:18:05 +0800 Subject: [PATCH 1/6] Fix StreamCreate failure handling --- src/brpc/stream.cpp | 5 +++- test/brpc_stream_create_unittest.cpp | 34 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 test/brpc_stream_create_unittest.cpp diff --git a/src/brpc/stream.cpp b/src/brpc/stream.cpp index a2a106a8b1..01504d3df6 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_stream_create_unittest.cpp b/test/brpc_stream_create_unittest.cpp new file mode 100644 index 0000000000..45bab8c073 --- /dev/null +++ b/test/brpc_stream_create_unittest.cpp @@ -0,0 +1,34 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include + +#include "brpc/controller.h" +#include "brpc/stream.h" + +class StreamCreateBugTest : public testing::Test {}; + +TEST_F(StreamCreateBugTest, create_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::StreamId second_stream = brpc::INVALID_STREAM_ID; + ASSERT_EQ(-1, brpc::StreamCreate(&second_stream, cntl, NULL)); + ASSERT_EQ(brpc::INVALID_STREAM_ID, second_stream); +} From 8cbf186abfd337e9f03d08f6add80a23254ab5a6 Mon Sep 17 00:00:00 2001 From: ljccjlljc <939159710@qq.com> Date: Wed, 8 Jul 2026 20:56:36 +0800 Subject: [PATCH 2/6] Add ScopedStream guard to stream test --- test/brpc_stream_create_unittest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/brpc_stream_create_unittest.cpp b/test/brpc_stream_create_unittest.cpp index 45bab8c073..9d346928a3 100644 --- a/test/brpc_stream_create_unittest.cpp +++ b/test/brpc_stream_create_unittest.cpp @@ -27,6 +27,7 @@ TEST_F(StreamCreateBugTest, create_twice_on_same_controller_returns_error) { 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)); From 373f57cdaa522db1210756a787a3675b9c09bd32 Mon Sep 17 00:00:00 2001 From: ljccjlljc <939159710@qq.com> Date: Thu, 9 Jul 2026 02:46:07 +0800 Subject: [PATCH 3/6] Move stream regression test into streaming UT --- test/brpc_stream_create_unittest.cpp | 35 ---------------------------- test/brpc_streaming_rpc_unittest.cpp | 12 ++++++++++ 2 files changed, 12 insertions(+), 35 deletions(-) delete mode 100644 test/brpc_stream_create_unittest.cpp diff --git a/test/brpc_stream_create_unittest.cpp b/test/brpc_stream_create_unittest.cpp deleted file mode 100644 index 9d346928a3..0000000000 --- a/test/brpc_stream_create_unittest.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#include - -#include "brpc/controller.h" -#include "brpc/stream.h" - -class StreamCreateBugTest : public testing::Test {}; - -TEST_F(StreamCreateBugTest, create_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); -} diff --git a/test/brpc_streaming_rpc_unittest.cpp b/test/brpc_streaming_rpc_unittest.cpp index 6a3b7b9e42..fc82fcde4e 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); +} From b6d95ea82b47a4478679c843d97756d718faea33 Mon Sep 17 00:00:00 2001 From: ljccjlljc <939159710@qq.com> Date: Thu, 25 Jun 2026 00:18:05 +0800 Subject: [PATCH 4/6] Fix StreamCreate failure handling --- test/brpc_stream_create_unittest.cpp | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/brpc_stream_create_unittest.cpp diff --git a/test/brpc_stream_create_unittest.cpp b/test/brpc_stream_create_unittest.cpp new file mode 100644 index 0000000000..45bab8c073 --- /dev/null +++ b/test/brpc_stream_create_unittest.cpp @@ -0,0 +1,34 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include + +#include "brpc/controller.h" +#include "brpc/stream.h" + +class StreamCreateBugTest : public testing::Test {}; + +TEST_F(StreamCreateBugTest, create_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::StreamId second_stream = brpc::INVALID_STREAM_ID; + ASSERT_EQ(-1, brpc::StreamCreate(&second_stream, cntl, NULL)); + ASSERT_EQ(brpc::INVALID_STREAM_ID, second_stream); +} From 3a34ad5001f32e15eeb09dac7803f9a4072f6527 Mon Sep 17 00:00:00 2001 From: ljccjlljc <939159710@qq.com> Date: Wed, 8 Jul 2026 20:56:36 +0800 Subject: [PATCH 5/6] Add ScopedStream guard to stream test --- test/brpc_stream_create_unittest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/brpc_stream_create_unittest.cpp b/test/brpc_stream_create_unittest.cpp index 45bab8c073..9d346928a3 100644 --- a/test/brpc_stream_create_unittest.cpp +++ b/test/brpc_stream_create_unittest.cpp @@ -27,6 +27,7 @@ TEST_F(StreamCreateBugTest, create_twice_on_same_controller_returns_error) { 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)); From 0f24d71aadd0634ec54f14ca5ae99db5da17e357 Mon Sep 17 00:00:00 2001 From: ljccjlljc <939159710@qq.com> Date: Thu, 9 Jul 2026 02:46:07 +0800 Subject: [PATCH 6/6] Move stream regression test into streaming UT --- test/brpc_stream_create_unittest.cpp | 35 ---------------------------- 1 file changed, 35 deletions(-) delete mode 100644 test/brpc_stream_create_unittest.cpp diff --git a/test/brpc_stream_create_unittest.cpp b/test/brpc_stream_create_unittest.cpp deleted file mode 100644 index 9d346928a3..0000000000 --- a/test/brpc_stream_create_unittest.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#include - -#include "brpc/controller.h" -#include "brpc/stream.h" - -class StreamCreateBugTest : public testing::Test {}; - -TEST_F(StreamCreateBugTest, create_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); -}