Skip to content

Make enabled_protocols authoritative for http and h2 - #3767

Open
wwbmmm wants to merge 1 commit into
apache:masterfrom
wwbmmm:oncall/req-20261121-025731-2
Open

wwbmmm wants to merge 1 commit into
apache:masterfrom
wwbmmm:oncall/req-20261121-025731-2

Conversation

@wwbmmm

@wwbmmm wwbmmm commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Problem Summary:

ServerOptions.enabled_protocols is documented as the list of protocols to serve, but Server::BuildAcceptor() always exempted http/h2 (and rdma_handshake) from the whitelist. A server configured with enabled_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:

  • The whitelist is now authoritative: when enabled_protocols is non-empty, only the listed protocols are served. rdma_handshake remains always served because it only handles the transport level handshake and dispatches no request; this is documented explicitly.
  • If builtin services (has_builtin_services, true by default) or restful services are registered while the whitelist contains neither http nor h2, Server::Start() fails with an actionable error instead of leaving their HTTP surface in an undefined state.
  • Updated the ServerOptions.enabled_protocols comment and docs/en/server.md, docs/cn/server.md.
  • Tests: test/brpc_server_unittest.cpp covers a whitelist without http rejecting HTTP, a whitelist with http/h2 still serving builtin services, and the misconfiguration failures. test/rdma_test_helper.h disables builtin services since it whitelists only baidu_std.

Side effects:

  • Performance effects: none, the change only affects acceptor construction.
  • Breaking backward compatibility: yes. Deployments that relied on the undocumented http/h2 exemption must add http (or h2) to enabled_protocols, or set has_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 from test/ so that cert-relative tests find their files.

🤖 This PR was automatically created by brpc-oncall

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 http or h2.
  • 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 thread src/brpc/server.cpp
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 thread src/brpc/server.cpp
Comment on lines +779 to +781
<< (has_builtin_services
? "set ServerOptions.has_builtin_services=false."
: "remove the restful mappings.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants