Copilot commented on code in PR #3767:
URL: https://github.com/apache/brpc/pull/3767#discussion_r4717670542
##########
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:
At this point `AddServiceInternal()` has already inserted `service` into
`_fullname_service_map`, `_service_map`, and `_method_map`. Returning here
without undoing those inserts makes a failed `AddService()` leave the RESTful
service registered; a retry with corrected options can then hit a
duplicate-service error, and the server state no longer matches the failed
callback result. The subsequent RESTful validation failures call
`RemoveService(service)` for exactly this cleanup, so do the same on this path
before returning.
--
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]