Skip to content

Conversation

@bananacocodrilo
Copy link

resolver.UnregisterForTesting has been removed from grpc-go grpc/grpc-go#6471, this change is needed in order to update to grpc 1.59.0

@CLAassistant
Copy link

CLAassistant commented Sep 24, 2024

CLA assistant check
All committers have signed the CLA.

func NewDescriptorProviderReflection(args ReflectionArgs) (DescriptorProvider, error) {
r, deregisterScheme := GenerateAndRegisterManualResolver()
defer deregisterScheme()
r := GenerateAndRegisterManualResolver()
Copy link
Contributor

Choose a reason for hiding this comment

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

We're creating potential memory leak here.
Let's discuss potential solution with a custom resolver, i.e. to register only one resolver, and then reuse it for different services.

Copy link
Author

@bananacocodrilo bananacocodrilo Sep 26, 2024

Choose a reason for hiding this comment

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

I've looked into two options to address it:

Keep the manual resolver.

We can create the scheme deterministically (I'm thinking scheme = "dest-" + args.Service).
This allows us to use resolver.Get(scheme) to avoid creating unnecessary resolvers, and we also can keep an updated the list of peers in the resolver.

Use passthrough

This results in simpler code, but only allows to specify one peer.
If the peer-list file used contains outdated addresses this could make the reflection fail where otherwise it would have worked.


rb := resolver.Get(scheme)
if rb != nil {
if r, ok := rb.(*manual.Resolver); ok {
Copy link
Author

Choose a reason for hiding this comment

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

Manual resolvers implement both, Resolver and Builder.
r.InitialState(newState) will set the new list of peers the next time that Build is called

}
}

func TestResolverAlreadyExists(t *testing.T) {
Copy link
Author

Choose a reason for hiding this comment

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

Test creating a new resolver for the same service with a different list of peers

rb := resolver.Get(scheme)
if rb != nil {
if r, ok := rb.(*manual.Resolver); ok {
r.InitialState(newState)
Copy link
Contributor

Choose a reason for hiding this comment

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

InitialState doesn't use mutex inside, so it's a potential data race.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants