Repository navigation
service: with_interceptor_arc — register a shared Arc<dyn Interceptor> - #118
Merged
Merged
Conversation
with_interceptor takes ownership and Arc::news a fresh allocation, which is the right ergonomics for the common case (one interceptor, one service). It is wasteful — and surprising — when a single interceptor instance carries process-wide shared state (a connection pool, a token cache) and should be registered on multiple ConnectRpcServices: each with_interceptor call allocates a separate trait object even though the caller already has an Arc in hand. with_interceptor_arc accepts the caller's Arc<dyn Interceptor> directly. with_interceptor now delegates to it, so the only difference is who calls Arc::new. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
All contributors have signed the CLA ✍️ ✅ |
iainmcgin
marked this pull request as ready for review
May 19, 2026 22:30
aknott-ant
approved these changes
May 19, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Why
with_interceptortakesimpl InterceptorandArc::news it internally — the right ergonomics for the common case. But a server that mounts severalConnectRpcServices and wants the same interceptor instance on all of them — say an auth interceptor whose state (a connection pool, a token cache, a rate-limit counter) is process-wide — has no way to register theArc<dyn Interceptor>it already holds. Eachwith_interceptorcall allocates and stores a separate trait object.What
with_interceptor_arc(self, interceptor: Arc<dyn Interceptor>) -> Selfaccepts the caller'sArcdirectly.with_interceptornow delegates to it, so the only behavioral difference is who callsArc::new. Same ordering, sameArc<[..]>rebuild-on-registration, samemust_use.Confidence
with_interceptor_arc_shares_one_instanceregisters oneArc<dyn Interceptor>on two services and asserts the strong count is 3 (caller + 2 services), that cloning a service does not bump the count (the chain is shared viaArc<[..]>, not per-interceptor), and that dropping the services returns the count to 1.cargo test,cargo fmt,cargo clippy --all-targets -- -D warnings,cargo docall clean (no new warnings).🤖 Generated with Claude Code