Skip to content

Validate RPC response sockets - #3580

Merged
wwbmmm merged 3 commits into
apache:masterfrom
wasphin:fix-rpc-response-socket-binding
Oct 5, 2026
Merged

wwbmmm merged 3 commits into
apache:masterfrom
wasphin:fix-rpc-response-socket-binding

Conversation

@wasphin

@wasphin wasphin commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

What problem does this PR solve?

Problem Summary:

The protobuf RPC response handlers associate replies with a controller using
the correlation ID without checking the connection used by the matching
request attempt. A reply arriving on another connection can update that
controller, and a stale retry reply can update the response before being
ignored by the call-completion path.

What is changed and the side effects?

Changed:

  • Check the arrival socket against the sending socket before updating the
    controller in baidu_std, hulu_pbrpc, sofa_pbrpc, and public_pbrpc.
  • Match current attempts and unfinished backup attempts; drop unmatched
    replies and release the correlation ID lock.
  • Add regression coverage for matching and mismatched sockets, successful
    completion after a dropped reply, stale retry replies, and unfinished
    backup attempts.
  • Cover all four response handlers and real channel/server exchanges using
    supported single, pooled, and short connection types on an ephemeral port.

Side effects:

  • Performance effects: One request-attempt lookup and socket ID comparison
    per response.
  • Breaking backward compatibility: None for replies arriving on the request's
    sending connection. Direct response injection without a sending socket
    remains supported for existing internal callers.

Check List:

Check that responses arrive on the socket used by the matching request
attempt before updating the controller. Account for current attempts and
unfinished backup requests across the four protobuf RPC protocols.

Add Hulu response tests for matching and mismatched sockets while keeping
direct response injection compatible with existing internal callers.
Verify rejection and subsequent completion on the sending socket for
baidu_std, sofa_pbrpc, and public_pbrpc response handlers.

Exercise real channel/server calls across all four affected protocols and
their supported connection types using an ephemeral server port.

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.

Copilot review overview

🟡 Changes recommended

Unversioned responses can still complete real requests, and rejected streaming responses omit required stream cleanup.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Adds socket validation to prevent mismatched or stale protobuf RPC responses from updating controllers.

Changes:

  • Validates response socket and request-attempt correlation IDs.
  • Drops mismatched responses while preserving valid backup attempts.
  • Adds protocol-level and real RPC regression coverage.
File Description
src/​brpc/​details/​controller_private_accessor.h Adds attempt/socket matching logic.
src/​brpc/​policy/​baidu_rpc_protocol.cpp Validates baidu_std responses.
src/​brpc/​policy/​hulu_pbrpc_protocol.cpp Validates Hulu responses.
src/​brpc/​policy/​sofa_pbrpc_protocol.cpp Validates SOFA responses.
src/​brpc/​policy/​public_pbrpc_protocol.cpp Validates public_pbrpc responses.
test/​brpc_channel_unittest.cpp Tests baidu_std and real RPC exchanges.
test/​brpc_hulu_pbrpc_protocol_unittest.cpp Tests mismatches, retries, and backups.
test/​brpc_sofa_pbrpc_protocol_unittest.cpp Tests SOFA socket matching.
test/​brpc_public_pbrpc_protocol_unittest.cpp Tests public_pbrpc socket matching.

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

Comment thread src/brpc/details/controller_private_accessor.h
Comment thread src/brpc/policy/baidu_rpc_protocol.cpp
Accept the base correlation ID only for direct response injection without
a sending socket. Real requests must match a versioned attempt ID.

Reset all advertised streams on the arrival socket when rejecting a
baidu_std response. Extend the regression test to check both rejection
paths and successful completion by the valid response.

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.

Copilot review overview

🟢 Approval recommended

The matching logic is consistent with controller attempt lifecycle and has comprehensive regression coverage.

Review effort: Balanced
Findings: None

Resolved since last review (2)

@wwbmmm
wwbmmm merged commit df61171 into apache:master Oct 5, 2026
25 checks passed
@wasphin
wasphin deleted the fix-rpc-response-socket-binding branch October 5, 2026 04:48
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.

3 participants