Skip to content

core: reference-count shared transport factory for OOB channels - #12985

Merged
kannanjgithub merged 2 commits into
grpc:masterfrom
kannanjgithub:oob-forwarding-transport-factory
Aug 13, 2026
Merged

core: reference-count shared transport factory for OOB channels#12985
kannanjgithub merged 2 commits into
grpc:masterfrom
kannanjgithub:oob-forwarding-transport-factory

Conversation

@kannanjgithub

@kannanjgithub kannanjgithub commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

When a main channel enters IDLE mode (e.g. after 30 minutes of inactivity), it shuts down its Load Balancer (such as RLS). This in turn shuts down any Out-of-Band child channels created by the LB. Previously, when an OOB channel finished terminating, it called transportFactory.close(), which prematurely closed the parent channel's shared ClientTransportFactory (NettyTransportFactory). As a result, when the main channel later attempted to exit IDLE mode or reconnect, transportFactory.newClientTransport() threw IllegalStateException: The transport factory is closed, causing an uncaught exception panic in the SynchronizationContext.

This change introduces RefCountedClientTransportFactory to track active references to the underlying ClientTransportFactory. When OOB channels inherit originalTransportFactory via createResolvingOobChannelBuilder(), retain() is invoked. Calling close() on the transport factory now decrements the reference count, ensuring the underlying delegate factory is only closed when all parent and child channel references have been released.

b/545260270

When a main channel enters IDLE mode (e.g. after 30 minutes of inactivity),
it shuts down its Load Balancer (such as RLS or xDS). This in turn shuts down
any Out-of-Band (OOB) child channels created by the LB. Previously, when an OOB
channel finished terminating, it called `transportFactory.close()`, which
prematurely closed the parent channel's shared `ClientTransportFactory`
(`NettyTransportFactory`). As a result, when the main channel later attempted
to exit IDLE mode or reconnect, `transportFactory.newClientTransport()` threw
`IllegalStateException: The transport factory is closed`, causing an uncaught
exception panic in the SynchronizationContext.

This change introduces `RefCountedClientTransportFactory` to track active
references to the underlying `ClientTransportFactory`. When OOB channels inherit
`originalTransportFactory` via `createResolvingOobChannelBuilder()`, `retain()`
is invoked. Calling `close()` on the transport factory now decrements the
reference count, ensuring the underlying delegate factory is only closed when all
parent and child channel references have been released.
@kannanjgithub
kannanjgithub requested a review from ejona86 August 12, 2026 12:26

@ejona86 ejona86 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not wild about needing to refcount, but I agree that is very appropriate for now. We should come back to the non-ChannelCredentials code paths at some point and see if we can reduce how often they occur.

Comment thread core/src/main/java/io/grpc/internal/RefCountedClientTransportFactory.java Outdated
Comment on lines 1485 to 1486
public ClientTransportFactory buildClientTransportFactory() {
return transportFactory;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This shows we really didn't think about the lifetimes involved here. We are relying on the caller actually building the returned builder (to avoid leaking the transport factory) and to not build multiple times.

callCredentials prevents us from trivially moving the transportFactory creation into this method. We should revisit this code at some point to see if we can make it sound.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a TODO for now.

@kannanjgithub
kannanjgithub merged commit 72c6e5f into grpc:master Aug 13, 2026
18 checks passed
@kannanjgithub
kannanjgithub deleted the oob-forwarding-transport-factory branch August 13, 2026 05:58
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