You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by "rajvarun77 (via GitHub)" <gi...@apache.org> on 2026/06/15 17:10:23 UTC
[PR] Add socket reserve/use connection affinity + fd_version primitives (brpc)
rajvarun77 opened a new pull request, #3348:
URL: https://github.com/apache/brpc/pull/3348
Generic `Controller`/`Socket` plumbing that lets a protocol pin a pooled/short connection across multiple RPCs (connection affinity). This is the shared substrate extracted from the MySQL client PR #3330 so it can be reviewed independently; #3330 is now stacked on top of this branch and contains only the MySQL-specific code.
### Controller
- `BindSockAction {NONE,RESERVE,USE}` encoded in two `Controller::_flags` bits (`FLAGS_BIND_SOCK_RESERVE`/`USE`) via `set_bind_sock_action()`/`bind_sock_action()` — no dedicated member added to the hot `Controller`.
- `_bind_sock` holds a socket reserved by a previous RPC. `EndRPC` propagates the action to the current `Call`; `Call::OnComplete` reserves the socket (on success) instead of returning it to the pool / failing it; `IssueRPC` reuses the reserved socket when the action is `USE`.
- `_session_data`: opaque per-RPC slot a protocol codec may use to carry typed state between serialize/pack/parse (not owned by `Controller`).
### Socket
- `_fd_version` (relaxed atomic, bumped on every `ResetFileDescriptor`) + `fd_version()` accessor — an ABA guard so an affinity holder can detect that a reserved fd was reconnected underneath it. Atomic because it is written on the reconnect path (no socket lock held) and read from other threads.
- `Socket::Write` accepts an empty buffer when `WriteOptions::auth_flags` is set, for server-greets-first handshakes that send their first bytes from the connection-phase handler rather than from `data`.
### Backup/retry fix
Also fixes an uninitialized read this machinery would otherwise introduce: the `Call(Call*)` copy constructor used for backup requests and retries did not initialize `bind_sock_action`, so `OnComplete` could read indeterminate bits and (when they matched `RESERVE`/`USE`) divert the backup call's socket away from the pool-return path, hanging the RPC (manifested as `ChannelTest.backup_request` timing out). Initialized to `BIND_SOCK_NONE`, matching `Call::Reset()`; a backup/retry never inherits affinity.
No protocol uses these primitives in this PR; the first consumer is MySQL (#3330).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Add socket reserve/use connection affinity + fd_version primitives (brpc)
Posted by "rajvarun77 (via GitHub)" <gi...@apache.org>.
rajvarun77 commented on PR #3348:
URL: https://github.com/apache/brpc/pull/3348#issuecomment-4710426190
Reverting the split — folding the backup/retry copy-constructor fix back into #3330 directly; a separate core PR isn't warranted for a one-line initialization fix.
--
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: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Add socket reserve/use connection affinity + fd_version primitives (brpc)
Posted by "rajvarun77 (via GitHub)" <gi...@apache.org>.
rajvarun77 commented on PR #3348:
URL: https://github.com/apache/brpc/pull/3348#issuecomment-4710392604
This is the shared-core substrate extracted from #3330 (MySQL client protocol), which is now stacked on top of this PR. Reviewing this first keeps the generic `Controller`/`Socket` change small and self-contained.
--
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: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Add socket reserve/use connection affinity + fd_version primitives (brpc)
Posted by "rajvarun77 (via GitHub)" <gi...@apache.org>.
rajvarun77 closed pull request #3348: Add socket reserve/use connection affinity + fd_version primitives
URL: https://github.com/apache/brpc/pull/3348
--
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: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org