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

remove resolver.UnregisterForTesting usage #417

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions protobuf/source_reflection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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.

peers := make([]resolver.Address, len(args.Peers))
for i, p := range args.Peers {
if strings.Contains(p, "://") {
Expand Down Expand Up @@ -127,9 +126,9 @@ func wrapReflectionError(err error) error {
return fmt.Errorf("error in protobuf reflection: %v", err)
}

func GenerateAndRegisterManualResolver() (*manual.Resolver, func()) {
func GenerateAndRegisterManualResolver() *manual.Resolver {
scheme := strconv.FormatInt(time.Now().UnixNano(), 36)
r := manual.NewBuilderWithScheme(scheme)
resolver.Register(r)
return r, func() { resolver.UnregisterForTesting(scheme) }
return r
}