wwbmmm commented on code in PR #3767:
URL: https://github.com/apache/brpc/pull/3767#discussion_r4657934640


##########
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:
   [replied by brpc-oncall robot] Fixed: `HasRestfulServices()` now checks 
`RestfulMap::size()` for both the global and the per-service maps, so maps left 
empty by `RemoveService()` no longer trigger the failure. Added 
`removed_restful_services_do_not_require_http` to cover this.



##########
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:
   [replied by brpc-oncall robot] Fixed: the message now lists every cause that 
applies and the matching remedy, e.g. "builtin and restful services are enabled 
... set ServerOptions.has_builtin_services=false and remove the restful 
mappings."



-- 
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]

Reply via email to