1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Serialize embedded resolver Start and Stop

Signed-off-by: Santhosh Manohar <santhosh@docker.com>
This commit is contained in:
Santhosh Manohar 2016-11-21 11:08:41 -08:00
parent 380be4c029
commit 94845a80f7

View file

@ -87,6 +87,7 @@ type resolver struct {
listenAddress string
proxyDNS bool
resolverKey string
startCh chan struct{}
}
func init() {
@ -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),
}
}
@ -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
@ -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()
}