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

Serialize embedded resolver Start and Stop #1561

Merged
merged 1 commit into from
Nov 21, 2016
Merged
Changes from all commits
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
8 changes: 8 additions & 0 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type resolver struct {
listenAddress string
proxyDNS bool
resolverKey string
startCh chan struct{}
}

func init() {
Expand All @@ -101,6 +102,7 @@ func NewResolver(address string, proxyDNS bool, resolverKey string, backend DNSB
listenAddress: address,
resolverKey: resolverKey,
err: fmt.Errorf("setup not done yet"),
startCh: make(chan struct{}, 1),
}
}

Expand Down Expand Up @@ -136,6 +138,9 @@ func (r *resolver) SetupFunc(port int) func() {
}

func (r *resolver) Start() error {
r.startCh <- struct{}{}
defer func() { <-r.startCh }()

// make sure the resolver has been setup before starting
if r.err != nil {
return r.err
Expand All @@ -160,6 +165,9 @@ func (r *resolver) Start() error {
}

func (r *resolver) Stop() {
r.startCh <- struct{}{}
defer func() { <-r.startCh }()

if r.server != nil {
r.server.Shutdown()
}
Expand Down