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


##########
src/brpc/server.cpp:
##########
@@ -1209,6 +1279,12 @@ int Server::StartInternal(const butil::EndPoint& 
endpoint,
         LOG(ERROR) << "Only IPv4 address supports port range feature";
         return -1;
     }
+    // Acceptors cache the protocol handlers built from ServerOptions, which 
may
+    // change between Start()s of the same Server, so rebuild them.
+    delete _am;
+    _am = nullptr;
+    delete _internal_am;
+    _internal_am = nullptr;

Review Comment:
   [replied by brpc-oncall robot] Fixed: `Acceptor::Join()` now waits while 
`_listened_fd >= 0`, so fd 0 is handled like any other listened fd and `-1` 
remains the only recycled sentinel.



##########
src/brpc/server.cpp:
##########
@@ -714,14 +792,10 @@ Acceptor* Server::BuildAcceptor() {
             // The protocol does not support server-side.
             continue;
         }
-        // Erase whatever the exemptions below say. http, h2 and
-        // rdma_handshake are always served, but they are still
-        // valid names for the whitelist.
-        bool in_whitelist = (whitelist.erase(protocols[i].name) != 0);
-        if (has_whitelist && !in_whitelist &&
-            !is_http_protocol(protocols[i].name) &&
+        if (has_whitelist && whitelist.count(protocols[i].name) == 0 &&
             !is_rdma_handshake_protocol(protocols[i].name)) {
-            // the protocol is not allowed to serve.
+            // rdma_handshake is always served since it only handles the
+            // transport level handshake and dispatches no request.
             RPC_VLOG << "Skip protocol=" << protocols[i].name;
             continue;

Review Comment:
   [replied by brpc-oncall robot] Fixed: `InitALPNOptions()` rejects any alpn 
whose protocol is not in `enabled_protocols` (`errno=EINVAL`), so a TLS client 
can no longer negotiate a protocol without an installed handler. Test: 
`enabled_protocols_must_include_alpn_protocols`.



##########
src/brpc/server.cpp:
##########
@@ -686,24 +686,102 @@ int Server::AddBuiltinServices() {
     return 0;
 }
 
-BUTIL_FORCE_INLINE bool is_http_protocol(const char* name) {
-    if (name[0] != 'h') {
-        return false;
+BUTIL_FORCE_INLINE bool is_rdma_handshake_protocol(const char* name) {
+    return strcmp(name, "rdma_handshake") == 0;
+}
+
+// Restful services are served through http/h2 requests. Empty maps may be
+// left by RemoveService(), so check the number of mappings instead of the
+// existence of the map.
+static bool HasRestfulServices(const Server::ServiceMap& services,
+                               const RestfulMap* global_restful_map) {
+    if (global_restful_map != nullptr && global_restful_map->size() != 0) {
+        return true;

Review Comment:
   [replied by brpc-oncall robot] Fixed: `ClearServices()` now deletes 
`_global_restful_map` as well, so cleared services leave no mappings behind, 
and `cleared_restful_services_do_not_require_http` covers a `baidu_std`-only 
`Start()` after `ClearServices()`.



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