Repository navigation
Conversation
ServerOptions.enabled_protocols is documented as the only protocols to serve, but BuildAcceptor always exempted http/h2 (and rdma_handshake) from the whitelist. An operator setting enabled_protocols="baidu_std" still served the whole HTTP/1 and HTTP/2 stacks, including builtin services on the main port, without any error or warning. Only rdma_handshake stays exempt since it handles the transport level handshake and dispatches no request. A whitelist without http or h2 while builtin or restful services are enabled now fails Server::Start() with an actionable message instead of silently serving or dropping them. Update the option comment and docs/en, docs/cn accordingly.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Two moderate active findings remain in src/brpc/server.cpp: the HTTP-only check treats empty RESTful maps as present and its diagnostic does not account for mappings that still cause startup failure.
2 open issues
What changed in this PR
This PR makes ServerOptions.enabled_protocols authoritative for HTTP/1 and HTTP/2 while preserving the transport-level rdma_handshake exception, and adds validation for HTTP-dependent services.
Changes:
- Restricts acceptor construction to explicitly whitelisted protocols.
- Validates builtin and RESTful service configurations that require
httporh2. - Updates server documentation, unit tests, and RDMA test configuration.
| File | Description |
|---|---|
| test/rdma_test_helper.h | Disables builtin services for RDMA tests that use a baidu_std-only protocol whitelist. |
| test/brpc_server_unittest.cpp | Adds tests covering HTTP exclusion, service availability, and invalid protocol whitelist configurations. |
| src/brpc/server.h | Documents the authoritative protocol whitelist behavior and HTTP service requirements. |
| src/brpc/server.cpp | Enforces protocol filtering and validates configurations for HTTP-dependent services. |
| docs/en/server.md | Documents the updated protocol whitelist semantics and configuration examples in English. |
| docs/cn/server.md | Documents the updated protocol whitelist semantics and configuration examples in Chinese. |
Review effort: Lite
Comment on lines
+697
to
+705
| 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; | ||
| } | ||
| } |
Comment on lines
+779
to
+781
| << (has_builtin_services | ||
| ? "set ServerOptions.has_builtin_services=false." | ||
| : "remove the restful mappings."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What problem does this PR solve?
Problem Summary:
ServerOptions.enabled_protocolsis documented as the list of protocols to serve, butServer::BuildAcceptor()always exemptedhttp/h2(andrdma_handshake) from the whitelist. A server configured withenabled_protocols = "baidu_std"still served the complete HTTP/1 and HTTP/2 stacks, including builtin services on the main port, without any error or warning.What is changed and the side effects?
Changed:
enabled_protocolsis non-empty, only the listed protocols are served.rdma_handshakeremains always served because it only handles the transport level handshake and dispatches no request; this is documented explicitly.has_builtin_services, true by default) or restful services are registered while the whitelist contains neitherhttpnorh2,Server::Start()fails with an actionable error instead of leaving their HTTP surface in an undefined state.ServerOptions.enabled_protocolscomment anddocs/en/server.md,docs/cn/server.md.test/brpc_server_unittest.cppcovers a whitelist without http rejecting HTTP, a whitelist with http/h2 still serving builtin services, and the misconfiguration failures.test/rdma_test_helper.hdisables builtin services since it whitelists onlybaidu_std.Side effects:
http(orh2) toenabled_protocols, or sethas_builtin_services = false;Server::Start()now fails with a message explaining both options instead of silently serving HTTP.Tests run:
build/test/brpc_server_unittest(all 54 tests), executed fromtest/so that cert-relative tests find their files.🤖 This PR was automatically created by brpc-oncall