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 1b075b203 Fix bound InputMessenger non-protocol handlers (#3714)
1b075b203 is described below
commit 1b075b2032126d09b41af3803bc4ccea47bb99dc
Author: nkysg <[email protected]>
AuthorDate: Sat Nov 21 16:18:30 2026 +0800
Fix bound InputMessenger non-protocol handlers (#3714)
* fix: bound InputMessenger non-protocol handlers
* Fix non-protocol handler capacity logging and test setup
---
src/brpc/input_messenger.cpp | 5 +++++
test/brpc_input_messenger_unittest.cpp | 12 ++++++++++++
2 files changed, 17 insertions(+)
diff --git a/src/brpc/input_messenger.cpp b/src/brpc/input_messenger.cpp
index 511121eb7..c6246423b 100644
--- a/src/brpc/input_messenger.cpp
+++ b/src/brpc/input_messenger.cpp
@@ -276,6 +276,11 @@ int InputMessenger::AddNonProtocolHandler(const
InputMessageHandler& handler) {
return -1;
}
const int index = _max_index.load(butil::memory_order_relaxed) + 1;
+ if (static_cast<size_t>(index) >= _capacity) {
+ LOG(ERROR) << "Non-protocol handler capacity exhausted (index="
+ << index << ", capacity=" << _capacity << ')';
+ return -1;
+ }
_handlers[index] = handler;
_max_index.store(index, butil::memory_order_release);
return 0;
diff --git a/test/brpc_input_messenger_unittest.cpp
b/test/brpc_input_messenger_unittest.cpp
index d385634a7..d74ae354e 100644
--- a/test/brpc_input_messenger_unittest.cpp
+++ b/test/brpc_input_messenger_unittest.cpp
@@ -62,6 +62,18 @@ protected:
};
};
+TEST_F(MessengerTest, non_protocol_handlers_respect_capacity) {
+ brpc::InputMessenger messenger(1);
+ brpc::InputMessageHandler handler;
+ handler.parse = brpc::policy::ParseHuluMessage;
+ handler.process = EmptyProcessHuluRequest;
+ handler.verify = nullptr;
+ handler.arg = nullptr;
+ handler.name = "dummy_hulu";
+ ASSERT_EQ(0, messenger.AddNonProtocolHandler(handler));
+ ASSERT_EQ(-1, messenger.AddNonProtocolHandler(handler));
+}
+
#define USE_UNIX_DOMAIN_SOCKET 1
const size_t NEPOLL = 1;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]