Split the error handling from Consul Catalog (deadlock)

This commit is contained in:
Or Tzabary 2018-07-05 16:12:03 +03:00 committed by Traefiker Bot
parent b1836587f2
commit f323df466d

View file

@ -1,7 +1,6 @@
package consulcatalog package consulcatalog
import ( import (
"errors"
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
@ -155,14 +154,8 @@ func (p *Provider) watch(configurationChan chan<- types.ConfigMessage, stop chan
defer close(stopCh) defer close(stopCh)
defer close(watchCh) defer close(watchCh)
for { safe.Go(func() {
select { for index := range watchCh {
case <-stop:
return nil
case index, ok := <-watchCh:
if !ok {
return errors.New("consul service list nil")
}
log.Debug("List of services changed") log.Debug("List of services changed")
nodes, err := p.getNodes(index) nodes, err := p.getNodes(index)
if err != nil { if err != nil {
@ -173,6 +166,13 @@ func (p *Provider) watch(configurationChan chan<- types.ConfigMessage, stop chan
ProviderName: "consul_catalog", ProviderName: "consul_catalog",
Configuration: configuration, Configuration: configuration,
} }
}
})
for {
select {
case <-stop:
return nil
case err := <-errorCh: case err := <-errorCh:
return err return err
} }