Skip to content

Commit

Permalink
Serialize embedded resolver Start and Stop
Browse files Browse the repository at this point in the history
Signed-off-by: Santhosh Manohar <[email protected]>
  • Loading branch information
Santhosh Manohar committed Nov 21, 2016
1 parent f054adc commit 3381972
Showing 1 changed file with 8 additions and 0 deletions.
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

0 comments on commit 3381972

Please sign in to comment.