Skip to content

remove resolver.UnregisterForTesting usage#417

Closed
bananacocodrilo wants to merge 0 commit into
yarpc:devfrom
bananacocodrilo:dev
Closed

remove resolver.UnregisterForTesting usage#417
bananacocodrilo wants to merge 0 commit into
yarpc:devfrom
bananacocodrilo:dev

Conversation

@bananacocodrilo

Copy link
Copy Markdown
Contributor

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

CLAassistant commented Sep 24, 2024

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread protobuf/source_reflection.go Outdated
func NewDescriptorProviderReflection(args ReflectionArgs) (DescriptorProvider, error) {
r, deregisterScheme := GenerateAndRegisterManualResolver()
defer deregisterScheme()
r := GenerateAndRegisterManualResolver()

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.

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.

@bananacocodrilo bananacocodrilo Sep 26, 2024

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.

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.

Comment thread protobuf/source_reflection.go Outdated

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

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.

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

Comment thread protobuf/source_reflection_test.go Outdated
}
}

func TestResolverAlreadyExists(t *testing.T) {

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.

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

Comment thread protobuf/source_reflection.go Outdated
rb := resolver.Get(scheme)
if rb != nil {
if r, ok := rb.(*manual.Resolver); ok {
r.InitialState(newState)

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.

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