Copilot commented on code in PR #3481:
URL: https://github.com/apache/brpc/pull/3481#discussion_r3838942213
##########
src/brpc/stream.cpp:
##########
@@ -758,7 +769,7 @@ int Stream::SetHostSocket(Socket* host_socket) {
return -1;
}
if (_host_socket != nullptr) {
- return 0;
+ return _host_socket->id() == host_socket->id() ? 0 : -1;
}
Review Comment:
`Stream::SetHostSocket()` now returns `-1` when the stream is already bound
to a different socket, but several existing callers ignore the return value
(e.g. `src/brpc/policy/baidu_rpc_protocol.cpp:375`,
`src/brpc/controller.cpp:1748`). That can leave the stream bound to an
unexpected socket with no error propagation. Consider updating call sites to
handle the failure (or making the mismatch a CHECK/log) so a mismatched binding
can’t silently proceed.
##########
test/brpc_streaming_rpc_unittest.cpp:
##########
@@ -81,6 +81,126 @@ class StreamingRpcTest : public testing::Test {
test::EchoResponse response;
};
+class StreamingRpcAuthenticator : public brpc::Authenticator {
+public:
+ int GenerateCredential(std::string* auth_str) const override {
+ *auth_str = "credential";
+ return 0;
+ }
+
+ int VerifyCredential(const std::string& auth_str,
+ const butil::EndPoint&,
+ brpc::AuthContext*) const override {
+ return auth_str == "credential" ? 0 : brpc::ERPCAUTH;
+ }
+};
+
+class AuthenticatedStreamHandler : public brpc::StreamInputHandler {
+public:
+ int on_received_messages(brpc::StreamId,
+ butil::IOBuf* const messages[],
+ size_t size) override {
+ for (size_t i = 0; i < size; ++i) {
+ if (messages[i]->to_string() == "authenticated stream frame") {
+ _received.store(true, std::memory_order_release);
+ }
+ }
+ return 0;
+ }
+
+ void on_idle_timeout(brpc::StreamId) override {}
+ void on_closed(brpc::StreamId) override {}
+ void on_failed(brpc::StreamId, int, const std::string&) override {}
+
+ bool received() const {
+ return _received.load(std::memory_order_acquire);
+ }
+
+private:
+ std::atomic<bool> _received{false};
+};
+
+TEST_F(StreamingRpcTest, reject_stream_frame_from_unauthenticated_socket) {
+ StreamingRpcAuthenticator auth;
+ brpc::Server server;
+ server._options.auth = &auth;
Review Comment:
This test directly assigns to `server._options.auth`, but `_options` is a
private member of `brpc::Server` (see `src/brpc/server.h:778`), so this will
not compile. Configure auth via `ServerOptions` (e.g. `Start(0, ...)`) so
`server.options().auth` is set through the public API.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]