Skip to content

fix(datastore): avoid copying auto-generated channelProvider in toBuilder - #15415

Open
jinseopkim0 wants to merge 1 commit into
mainfrom
fix/datastore-tobuilder-channel-provider
Open

jinseopkim0 wants to merge 1 commit into
mainfrom
fix/datastore-tobuilder-channel-provider

Conversation

@jinseopkim0

@jinseopkim0 jinseopkim0 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

b/588887355

Track caller-supplied customChannelProvider separately in DatastoreOptions so toBuilder() does not carry over an auto-generated gRPC channelProvider whose baked-in endpoint or telemetry configurator may become stale.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a hasCustomChannelProvider flag in DatastoreOptions to track whether the TransportChannelProvider was explicitly provided or auto-generated. This ensures that auto-generated providers are correctly cleared and rebuilt when configuration settings like host, transport options, universe domain, or OpenTelemetry options change. The review feedback correctly identifies a serialization issue where hasCustomChannelProvider is not marked as transient, which could lead to inconsistent state and stale endpoints after deserialization since channelProvider itself is transient.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a hasCustomChannelProvider flag to DatastoreOptions to track whether a channel provider was explicitly supplied by the caller. This ensures that auto-generated channel providers are correctly cleared and rebuilt when configuration settings like transport options, host, universe domain, or OpenTelemetry options are modified. The review feedback suggests several improvements: adding null checks to prevent a potential NullPointerException when comparing transport options, and checking if the host, universe domain, or OpenTelemetry options have actually changed before clearing the channel provider to avoid unnecessary recreation.

@jinseopkim0
jinseopkim0 requested a review from lqiu96 December 3, 2026 00:03
@jinseopkim0
jinseopkim0 marked this pull request as ready for review December 3, 2026 00:03
@jinseopkim0
jinseopkim0 requested a review from a team as a code owner December 3, 2026 00:03
@jinseopkim0
jinseopkim0 enabled auto-merge (squash) December 3, 2026 00:07
Comment on lines +244 to +246
// Setting a non-null provider marks it as caller-owned so later host/universe changes do not
// discard it; passing null reverts to auto-generated provider behavior.
this.hasCustomChannelProvider = channelProvider != null;

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.

taking a look at this and I think I'm missing the issue here. Though I think this does bring in some interesting behavior that we should try to standardize via Gax/ Datastore.

Gax endpoint resolution works like this:

  1. TransportchannelProvider configures an endpoint (use this first if set )
  2. Client#setEndpoint configures (then use this)
  3. configure default via UD

I think we already check for transportchannelprovider to be non-null for gRPC only (http doesn't seem to support setting a transportchannelprovider).

IIUC, perhaps we just need to update the logic to capture the custom host to also account for any endpoint set via TransportchannelProvider?

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.

Thanks for the feedback. When built with a custom host and no explicit channelProvider, DatastoreOptions auto-generates an InstantiatingGrpcChannelProvider with that host baked in. toBuilder() copied it, so later setHost(...) or setUniverseDomain(...) calls were overridden by the stale provider's endpoint (#1 above).

I simplified to only copy caller-supplied customChannelProvider in toBuilder(), removing the flag and setter overrides while preserving TransportChannelProvider precedence.

@jinseopkim0 jinseopkim0 changed the title fix(datastore): reset auto-generated channelProvider on toBuilder mutations fix(datastore): avoid copying auto-generated channelProvider in toBuilder Dec 3, 2026
@jinseopkim0
jinseopkim0 force-pushed the fix/datastore-tobuilder-channel-provider branch from 9fbd11e to 9c8958e Compare December 3, 2026 23:47
@jinseopkim0
jinseopkim0 requested a review from lqiu96 December 3, 2026 23:55

This branch has not been deployed

No deployments
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