-
Notifications
You must be signed in to change notification settings - Fork 35
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
remove resolver.UnregisterForTesting usage #417
base: dev
Are you sure you want to change the base?
Conversation
protobuf/source_reflection.go
Outdated
@@ -32,8 +32,7 @@ type ReflectionArgs struct { | |||
// NewDescriptorProviderReflection returns a DescriptorProvider that reaches | |||
// out to a reflection server to access file descriptors. | |||
func NewDescriptorProviderReflection(args ReflectionArgs) (DescriptorProvider, error) { | |||
r, deregisterScheme := GenerateAndRegisterManualResolver() | |||
defer deregisterScheme() | |||
r := GenerateAndRegisterManualResolver() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
@@ -196,6 +196,44 @@ func TestReflectionRoutingHeaders(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestResolverAlreadyExists(t *testing.T) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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