Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xds: decouple xds channel creation and bootstrapping #7764

Conversation

voidzcy
Copy link
Contributor

@voidzcy voidzcy commented Dec 28, 2020

Fixes #7752.

The singleton XdsClient ObjectPool is cached for the entire process. The bootstrap file is read at the time this ObjectPool is created. The shared XdsClient instance has a much shorter lifecycle than the ObjectPool as the instance is only created upon the first call of getObject() and is destroyed when its reference count reaches zero. The ObjectPool creates a new XdsClient instance after the previous one was destroyed.

The ownership and lifecycle of the xDS channel is wrong. Currently the singleton XdsClient ObjectPool owns the xDS channel and it uses the same xDS channel even when recreating a new XdsClient instance. However, the channel would have been shutdown by the XdsClient.

In this change:

  • Reading the bootstrap will determine and create the ChannelCredentials for each specified xDS server. An exception will be thrown if any xDS server specifies some channel_creds type that is not supported, not just for the first server (which is the only one to be used now).
  • Reading the bootstrap also determines the xDS protocol version.
  • The xDS channel will have the same lifecycle as the XdsClient instance: an xDS channel is created at the first call of getObject() and is shut down at the same time as the XdsClient is shutting down.

Main changes are in Bootstrapper.java and SharedXdsClientPoolProvider.java (and XdsClientWrapperForServerSds.java for server side XdsClient creation).

/cc @sanjaypujare

@@ -121,26 +134,27 @@ public XdsClient returnObject(Object object) {
if (refCount == 0) {
xdsClient.shutdown();
xdsClient = null;
channel.shutdownNow();
Copy link
Member

Choose a reason for hiding this comment

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

It can be shutdown more gracefully with shutdown(). As long as all xdsClients cancel their streams in xdsClient.shutdown(), the channel can be terminated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was unsure if we need to use shutdownNow() here to make sure it is quickly shut down. For cases like #7752, the reference to the current xDS channel may be quickly cleared and a new xDS channel is created. shutdownNow() seems to be safer, doesn't it? Is there any reason that shutdown() is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, as you said it doesn't actually matter much as long as streams are canceled when XdsClient shuts down. I am changing it to shutdown(), we will see if any problem will be encountered.

@voidzcy voidzcy force-pushed the bugfix/decouple_xds_channel_creation_and_bootstrapping branch from 1c0cf79 to d80d7a0 Compare December 29, 2020 01:34
@voidzcy voidzcy merged commit cddc1a5 into grpc:master Dec 29, 2020
dfawley pushed a commit to dfawley/grpc-java that referenced this pull request Jan 15, 2021
This change fixes the problem of mismatched lifecycle of the xDS channel and XdsClient. Reading the bootstrap will determine and create the ChannelCredentials for each specified xDS server. An exception will be thrown if any xDS server specifies some channel_creds type that is not supported, not just for the first server (which is the only one to be used now). Reading the bootstrap also determines the xDS protocol version. The xDS channel will have the same lifecycle as the XdsClient instance: an xDS channel is created at the first call of getObject() and is shut down at the same time as the XdsClient is shutting down. A new xDS channel will be created when the ObjectPool creates a new XdsClient instance.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xDS channel shutdown problem
2 participants