Skip to content

Allow enabled_protocols to name http, h2 and rdma_handshake - #3518

Open
chenBright wants to merge 1 commit into
apache:masterfrom
chenBright:fix_enabled_protocols
Open

Allow enabled_protocols to name http, h2 and rdma_handshake#3518
chenBright wants to merge 1 commit into
apache:masterfrom
chenBright:fix_enabled_protocols

Conversation

@chenBright

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

http, h2 and rdma_handshake are served whatever ServerOptions.enabled_protocols
says — the builtin services are only reachable over http/h2, and rdma_handshake is a
transport level handshake that dispatches no request. But naming any of them in
enabled_protocols made Server::Start() return -1:

enabled_protocols = "baidu_std http"           -> Server::Start() returns -1
enabled_protocols = "baidu_std h2"             -> Server::Start() returns -1
enabled_protocols = "baidu_std rdma_handshake" -> Server::Start() returns -1

In Server::BuildAcceptor() the exemption was tested before the whitelist lookup,
inside a single && chain:

if (has_whitelist &&
    !is_http_protocol(protocols[i].name) &&
    !is_rdma_handshake_protocol(protocols[i].name) &&
    !whitelist.erase(protocols[i].name)) {

For an exempted protocol the chain short-circuits at the third condition, so
whitelist.erase() never runs and the name is never consumed. It then survives into
the leftover check at the end of the function and comes back as:

ServerOptions.enabled_protocols has unknown protocols=`http '

So a user who spelled out every protocol they wanted — including the ones that are
always on anyway — could not start the server at all.

What is changed and the side effects?

Changed:

Side effects:

  • Performance effects:

  • Breaking backward compatibility:


Check List:

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.

🟢 Approval recommended

The core logic fix matches the stated problem and is covered by a focused regression test, with only a minor maintainability note remaining.

Pull request overview

This PR fixes ServerOptions.enabled_protocols handling so that specifying always-enabled protocol names (http, h2, rdma_handshake) no longer causes Server::Start() to fail due to leftover “unknown protocol” entries. This aligns enabled_protocols behavior with how the server actually serves builtin HTTP/H2 services and RDMA handshake traffic.

Changes:

  • Adjust Server::BuildAcceptor() to consume whitelisted protocol names even when they’re exempt from filtering (http/h2/rdma_handshake).
  • Add a unit test covering enabled_protocols values that include these always-enabled protocol names.
  • Clarify ServerOptions::enabled_protocols documentation regarding always-enabled protocols.
File summaries
File Description
src/brpc/server.cpp Fixes whitelist consumption logic in BuildAcceptor() so exempt protocols don’t remain as “unknown”.
src/brpc/server.h Documents that http/h2 and rdma_handshake are always served and may be listed in enabled_protocols without effect.
test/brpc_server_unittest.cpp Adds regression coverage to ensure naming always-enabled protocols in enabled_protocols doesn’t break Start().
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/brpc/server.cpp
@chenBright
chenBright requested a review from wwbmmm September 4, 2026 09:32
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