mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-28 15:09:39 -08:00
Merge pull request #2201 from prometheus/consul-race
discovery: terminate senders before closing channel
This commit is contained in:
commit
9b7e097a76
|
@ -18,6 +18,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
consul "github.com/hashicorp/consul/api"
|
consul "github.com/hashicorp/consul/api"
|
||||||
|
@ -132,7 +133,11 @@ func (cd *Discovery) shouldWatch(name string) bool {
|
||||||
|
|
||||||
// Run implements the TargetProvider interface.
|
// Run implements the TargetProvider interface.
|
||||||
func (cd *Discovery) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
func (cd *Discovery) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
defer close(ch)
|
var wg sync.WaitGroup
|
||||||
|
defer func() {
|
||||||
|
wg.Wait()
|
||||||
|
close(ch)
|
||||||
|
}()
|
||||||
|
|
||||||
// Watched services and their cancelation functions.
|
// Watched services and their cancelation functions.
|
||||||
services := map[string]func(){}
|
services := map[string]func(){}
|
||||||
|
@ -199,7 +204,11 @@ func (cd *Discovery) Run(ctx context.Context, ch chan<- []*config.TargetGroup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
wctx, cancel := context.WithCancel(ctx)
|
wctx, cancel := context.WithCancel(ctx)
|
||||||
go srv.watch(wctx, ch)
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
srv.watch(wctx, ch)
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
services[name] = cancel
|
services[name] = cancel
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue