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

xdsclient: race around resource subscriptions and unsubscsriptions #8125

Open
easwars opened this issue Feb 25, 2025 · 1 comment
Open

xdsclient: race around resource subscriptions and unsubscsriptions #8125

easwars opened this issue Feb 25, 2025 · 1 comment
Assignees
Labels
Area: xDS Includes everything xDS related, including LB policies used with xDS. Type: Bug

Comments

@easwars
Copy link
Contributor

easwars commented Feb 25, 2025

We are seeing a race with the xDS client when the application has multiple grpc channels being created and shutdown at the same time, repeatedly. One possible way to get this race to happen is for an application to open multiple grpc channels to the same target (around the same time), make one RPC in each channel, and shut it down, and do this process over and over again.

The sequence of events that trigger the race is as follows:

  • Channel 1 is created to target foo. It goes through the whole xDS flow successfully and is being shut down.
  • At around the same time, Channel 2 is created to the same target foo.
  • As part of Channel 1 shutdown, it starts unsubscribing to the xDS resources.
  • The xDS client function to unsubscribe schedules a callback on the serializer. The function returns early, but the actual work of sending the ADS request to effect the unsubscription happens asynchronously. See:
    func (a *authority) unwatchResource(rType xdsresource.Type, resourceName string, watcher xdsresource.ResourceWatcher) func() {
  • When the scheduled callback runs, two things happens:
  • Channel 2 starts out and gets a reference to the existing xDS client (when it attempts to create a new one). It registers a watch for the same LDS resource as channel 1.
  • The watch function in the xDS client sees that there is no such LDS resource in the cache (because it was deleted as part of the unsubscription by channel 1). So, it updates the cache and creates a placeholder for this resource. See: .
  • The actual ADS request for the subscription will be sent out asynchronously through the ADS stream implementation.
  • By the time the ADS stream implementation gets around to write the LDS request on the wire (both for the unsubscription by channel 1 and the subscription by channel 2), it sees there there is a single LDS resource to be requested, and it also sees a nonce and a version for that resource type. This is the same nonce and version that was received when the same resource was requested as part of channel 1. So, such a request is sent out, the management server does not send a response back, because it already responded to the same request name with the same version and nonce on the same ADS stream.

At this point channel 2 is stuck until the LDS resource-not-found timer fires after 15s and from that point on RPCs on the channel start to fail.

The fundamental reason behind this race is that the resource is deleted from the xDS client cache even before it is sent out of the ADS stream. Also important to note is that some resource state is maintained in the ADS stream implementation, while some is maintained in the xDS client and these both can go out of sync.

@easwars easwars self-assigned this Feb 25, 2025
@easwars easwars added the Area: xDS Includes everything xDS related, including LB policies used with xDS. label Feb 25, 2025
@easwars
Copy link
Contributor Author

easwars commented Feb 25, 2025

@purnesh42H

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: xDS Includes everything xDS related, including LB policies used with xDS. Type: Bug
Projects
None yet
Development

No branches or pull requests

1 participant