provider update race fix attempt

This commit is contained in:
yusing 2024-03-12 16:42:09 +00:00
parent a2ada5c7ea
commit 110bb362b3
2 changed files with 4 additions and 3 deletions

Binary file not shown.

View file

@ -41,11 +41,12 @@ func (p *Provider) StopAllRoutes() {
p.mutex.Lock() p.mutex.Lock()
defer p.mutex.Unlock() defer p.mutex.Unlock()
if !p.needUpdate() { if p.stopWatching == nil {
return return
} }
close(p.stopWatching) close(p.stopWatching)
p.stopWatching = nil
if p.dockerClient != nil { if p.dockerClient != nil {
p.dockerClient.Close() p.dockerClient.Close()
} }
@ -73,7 +74,6 @@ func (p *Provider) BuildStartRoutes() {
} }
p.lastUpdate = time.Now() p.lastUpdate = time.Now()
p.stopWatching = make(chan struct{})
p.routes = make(map[string]Route) p.routes = make(map[string]Route)
cfgs, err := p.GetProxyConfigs() cfgs, err := p.GetProxyConfigs()
@ -94,6 +94,7 @@ func (p *Provider) BuildStartRoutes() {
} }
p.WatchChanges() p.WatchChanges()
p.Logf("Build", "built %d routes", len(p.routes)) p.Logf("Build", "built %d routes", len(p.routes))
p.stopWatching = make(chan struct{})
} }
func (p *Provider) WatchChanges() { func (p *Provider) WatchChanges() {