Skip to content

unwrap ForwardingSubchannel during Picks#12658

Draft
shivaspeaks wants to merge 6 commits intogrpc:masterfrom
shivaspeaks:unwrap-forwarding-subchannel
Draft

unwrap ForwardingSubchannel during Picks#12658
shivaspeaks wants to merge 6 commits intogrpc:masterfrom
shivaspeaks:unwrap-forwarding-subchannel

Conversation

@shivaspeaks
Copy link
Member

@shivaspeaks shivaspeaks commented Feb 16, 2026

This PR ensures that Load Balancing (LB) policies unwrap ForwardingSubchannel instances before returning them in a PickResult.

Rationale: Currently, the identity of a subchannel is "awkward" because decorators break object identity. This forces the core channel to use internal workarounds like getInternalSubchannel() to find the underlying implementation. Removing these wrappers during the pick process is a critical prerequisite for deleting Subchannel Attributes.

By enforcing unwrapping, ManagedChannelImpl can rely on the fact that a returned subchannel is the same instance it originally created. This allows the channel to use strongly-typed fields for state management (via "blind casting") rather than loosely-typed attributes. This also paves the way for the eventual removal of the getInternalSubchannel() internal API.

New APIs: To ensure we don't "drop data on the floor" during the unwrapping process, this PR adds two new non-static APIs to PickResult:

  • copyWithSubchannel()
  • copyWithStreamTracerFactory()

Unlike static factory methods, these instance methods follow a "copy-and-update" pattern that preserves all existing pick-level metadata (such as authority overrides or drop status) while only swapping the specific field required.

@shivaspeaks shivaspeaks requested a review from ejona86 February 18, 2026 19:26
@shivaspeaks
Copy link
Member Author

Please also check the description of the PR, if we need to add anything or remove anything.

Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

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

You should probably mark this PR as "Ready for review" (not Draft).

loosely-typed attributes

Attributes are strongly-typed. It's more about not needing to abuse attributes so to re-discover what should already be known.


private static final class OrcaOobPicker extends SubchannelPicker {
private final SubchannelPicker delegate;
static final class OrcaOobPicker extends SubchannelPicker {
Copy link
Member

Choose a reason for hiding this comment

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

Add @VisibleForTesting to both of these.

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

Comments