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

Ensure that RoundRobin.Close() does not panic. #1139

Merged
merged 1 commit into from
May 5, 2017
Merged

Ensure that RoundRobin.Close() does not panic. #1139

merged 1 commit into from
May 5, 2017

Conversation

alecthomas
Copy link
Contributor

This can only occur due to programmer error, but is quite confusing when it does.

Here's an example that triggers it:

package main

import (
	"google.golang.org/grpc"
	"google.golang.org/grpc/naming"
)

type resolver struct {
}

// Resolve creates a Watcher for target.
func (resolver) Resolve(target string) (naming.Watcher, error) {
	return &watcher{addr: target}, nil
}

type watcher struct {
	addr string
}

func (w *watcher) Next() ([]*naming.Update, error) {
	if w.addr == "" {
		select {}
	}
	addr := w.addr
	w.addr = ""
	return []*naming.Update{{Addr: addr}}, nil
}
func (w *watcher) Close() {}

func main() {
	balancer := grpc.RoundRobin(&resolver{})
	_, err := grpc.Dial("127.0.0.1:1234", grpc.WithBalancer(balancer), grpc.WithInsecure())
	if err != nil {
		panic(err)
	}
	err = balancer.Close()
	if err != nil {
		panic(err)
	}
	err = balancer.Close()
	if err != nil {
		panic(err)
	}
	select {}
}

Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

Thanks for the fix. We will also do this for the grpclb balancer.

@dfawley dfawley merged commit ffa4ec7 into grpc:master May 5, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants