Copilot commented on code in PR #3767:
URL: https://github.com/apache/brpc/pull/3767#discussion_r4652639744
##########
src/brpc/server.cpp:
##########
@@ -686,17 +686,26 @@ int Server::AddBuiltinServices() {
return 0;
}
-BUTIL_FORCE_INLINE bool is_http_protocol(const char* name) {
- if (name[0] != 'h') {
- return false;
- }
- return strcmp(name, "http") == 0 || strcmp(name, "h2") == 0;
-}
-
BUTIL_FORCE_INLINE bool is_rdma_handshake_protocol(const char* name) {
return strcmp(name, "rdma_handshake") == 0;
}
+// Builtin and restful services are served through http/h2 requests.
+static bool HasHttpOnlyServices(const ServerOptions& options,
+ const Server::ServiceMap& services,
+ const RestfulMap* global_restful_map) {
+ if (options.has_builtin_services || global_restful_map != nullptr) {
+ return true;
+ }
+ for (Server::ServiceMap::const_iterator it = services.begin();
+ it != services.end(); ++it) {
+ if (it->second.restful_map != nullptr) {
+ return true;
+ }
+ }
Review Comment:
This tests only whether a `RestfulMap` object exists, not whether it
contains any mappings. `RemoveService` deliberately leaves
`_global_restful_map` allocated after its last mapping is removed (the existing
server unit test observes `size() == 0`), and the virtual per-service maps can
likewise remain empty. Consequently, a server with no registered RESTful
endpoint can still fail `Start()` when `enabled_protocols` omits HTTP. Check
`size()` for both the global and per-service maps before treating them as
HTTP-only services.
##########
src/brpc/server.cpp:
##########
@@ -749,6 +761,27 @@ Acceptor* Server::BuildAcceptor() {
LOG(ERROR) << err.str();
return nullptr;
}
+ if (has_whitelist && !http_in_whitelist &&
+ HasHttpOnlyServices(_options, _fullname_service_map,
+ _global_restful_map)) {
+ // Serving neither http nor h2 makes builtin/restful services
+ // silently unreachable, reject the configuration instead.
+ const bool has_builtin_services = _options.has_builtin_services;
+ LOG(ERROR) << "ServerOptions.enabled_protocols=`"
+ << _options.enabled_protocols << "' enables neither http "
+ << "nor h2, but "
+ << (has_builtin_services
+ ? "ServerOptions.has_builtin_services is true"
+ : "restful services are added")
+ << ". Builtin and restful services are served through "
+ << "http/h2, add `http' (or `h2') to enabled_protocols, "
+ << "or "
+ << (has_builtin_services
+ ? "set ServerOptions.has_builtin_services=false."
+ : "remove the restful mappings.");
Review Comment:
When both builtin services and RESTful mappings are present, this branch
says that setting `has_builtin_services=false` is a fix, but the RESTful
mappings still make `HasHttpOnlyServices` return true, so `Start()` will fail
again unless those mappings are also removed. Please make the diagnostic
account for both causes (or state that disabling builtins and removing RESTful
mappings are both required).
--
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]