core: reference-count shared transport factory for OOB channels - #12985
Merged
kannanjgithub merged 2 commits intoAug 13, 2026
Merged
Conversation
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.
ejona86
approved these changes
Aug 12, 2026
ejona86
left a comment
Member
There was a problem hiding this comment.
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 on lines
1485
to
1486
| public ClientTransportFactory buildClientTransportFactory() { | ||
| return transportFactory; |
Member
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
Added a TODO for now.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 sharedClientTransportFactory(NettyTransportFactory). As a result, when the main channel later attempted to exit IDLE mode or reconnect,transportFactory.newClientTransport()threwIllegalStateException: The transport factory is closed, causing an uncaught exception panic in the SynchronizationContext.This change introduces
RefCountedClientTransportFactoryto track active references to the underlyingClientTransportFactory. When OOB channels inheritoriginalTransportFactoryviacreateResolvingOobChannelBuilder(),retain()is invoked. Callingclose()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