fix stuck loading in some scenerios for ls-* command line options

This commit is contained in:
yusing 2024-09-22 05:01:36 +08:00
parent 46281aa3b0
commit d9fd399e43
4 changed files with 13 additions and 9 deletions

View file

@ -249,7 +249,7 @@ func (cfg *Config) loadProviders(providers *M.ProxyProviders) (res E.NestedError
for name, dockerHost := range providers.Docker {
p, err := PR.NewDockerProvider(name, dockerHost)
if err != nil {
b.Add(err.Subject(dockerHost))
b.Add(err.Subjectf("%s (%s)", name, dockerHost))
continue
}
cfg.proxyProviders.Store(p.GetName(), p)

View file

@ -80,8 +80,6 @@ func main() {
return
}
cfg.StartProxyProviders()
if args.Command == common.CommandListRoutes {
printJSON(cfg.RoutesByAlias())
return
@ -92,6 +90,8 @@ func main() {
return
}
cfg.StartProxyProviders()
if err.HasError() {
l.Warn(err)
}
@ -177,10 +177,11 @@ func main() {
close(done)
}()
timeout := time.After(time.Duration(cfg.Value().TimeoutShutdown) * time.Second)
select {
case <-done:
logrus.Info("shutdown complete")
case <-time.After(time.Duration(cfg.Value().TimeoutShutdown) * time.Second):
case <-timeout:
logrus.Info("timeout waiting for shutdown")
}
}

View file

@ -143,10 +143,13 @@ func (p *Provider) GetRoute(alias string) (R.Route, bool) {
}
func (p *Provider) LoadRoutes() E.NestedError {
routes, err := p.LoadRoutesImpl()
p.routes = routes
p.l.Infof("loaded %d routes", routes.Size())
var err E.NestedError
p.routes, err = p.LoadRoutesImpl()
if p.routes.Size() > 0 {
p.l.Infof("loaded %d routes", p.routes.Size())
return err
}
return E.FailWith("loading routes", err)
}
func (p *Provider) watchEvents() {

View file

@ -72,9 +72,9 @@ func (w DockerWatcher) EventsWithOptions(ctx context.Context, options DockerList
if !w.client.Connected() {
var err E.NestedError
attempts := 0
for {
w.client, err = D.ConnectClient(w.host)
attempts := 0
if err != nil {
break
}