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


##########
src/brpc/server.cpp:
##########
@@ -1580,6 +1703,21 @@ int 
Server::AddServiceInternal(google::protobuf::Service* service,
     butil::StringPiece restful_mappings = svc_opt.restful_mappings;
     restful_mappings.trim_spaces();
     if (!restful_mappings.empty()) {
+        // Services added while Start() is running (e.g. from bthread_init_fn)
+        // were not seen by the validation of the user-provided options, so
+        // check that their restful mappings can be served as well.
+        if (_in_start) {
+            std::unordered_set<std::string> whitelist;
+            ParseEnabledProtocols(_options.enabled_protocols, &whitelist);
+            if (!whitelist.empty() && whitelist.count("http") == 0 &&
+                whitelist.count("h2") == 0) {
+                LOG(ERROR) << "Fail to add restful service=`" << 
sd->full_name()
+                           << "': ServerOptions.enabled_protocols=`"
+                           << _options.enabled_protocols
+                           << "' enables neither http nor h2";
+                return -1;
+            }
+        }

Review Comment:
   [replied by brpc-oncall robot] Fixed: the rejection path now calls 
`RemoveService(service)` before returning, like the other RESTful failure 
paths, so a failed `AddService()` leaves no registration behind. 
`restful_service_added_in_init_fn_is_rejected` now asserts `service_count() == 
0` after the failed `Start()` and that retrying with `http` enabled can add the 
same service and start successfully.



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