From 26d58865abdc9a1d7500e852575414e26e753842 Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Tue, 27 Jun 2017 16:22:57 -0500 Subject: [PATCH] Make sure to call cancel on the context --- watch/funcs.go | 7 +++++++ watch/watch.go | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/watch/funcs.go b/watch/funcs.go index dfc12220a..738343009 100644 --- a/watch/funcs.go +++ b/watch/funcs.go @@ -43,6 +43,7 @@ func keyWatch(params map[string]interface{}) (WatcherFunc, error) { fn := func(p *Plan) (uint64, interface{}, error) { kv := p.client.KV() opts := makeQueryOptionsWithContext(p, stale) + defer p.cancelFunc() pair, meta, err := kv.Get(key, &opts) if err != nil { return 0, nil, err @@ -72,6 +73,7 @@ func keyPrefixWatch(params map[string]interface{}) (WatcherFunc, error) { fn := func(p *Plan) (uint64, interface{}, error) { kv := p.client.KV() opts := makeQueryOptionsWithContext(p, stale) + defer p.cancelFunc() pairs, meta, err := kv.List(prefix, &opts) if err != nil { return 0, nil, err @@ -91,6 +93,7 @@ func servicesWatch(params map[string]interface{}) (WatcherFunc, error) { fn := func(p *Plan) (uint64, interface{}, error) { catalog := p.client.Catalog() opts := makeQueryOptionsWithContext(p, stale) + defer p.cancelFunc() services, meta, err := catalog.Services(&opts) if err != nil { return 0, nil, err @@ -110,6 +113,7 @@ func nodesWatch(params map[string]interface{}) (WatcherFunc, error) { fn := func(p *Plan) (uint64, interface{}, error) { catalog := p.client.Catalog() opts := makeQueryOptionsWithContext(p, stale) + defer p.cancelFunc() nodes, meta, err := catalog.Nodes(&opts) if err != nil { return 0, nil, err @@ -146,6 +150,7 @@ func serviceWatch(params map[string]interface{}) (WatcherFunc, error) { fn := func(p *Plan) (uint64, interface{}, error) { health := p.client.Health() opts := makeQueryOptionsWithContext(p, stale) + defer p.cancelFunc() nodes, meta, err := health.Service(service, tag, passingOnly, &opts) if err != nil { return 0, nil, err @@ -179,6 +184,7 @@ func checksWatch(params map[string]interface{}) (WatcherFunc, error) { fn := func(p *Plan) (uint64, interface{}, error) { health := p.client.Health() opts := makeQueryOptionsWithContext(p, stale) + defer p.cancelFunc() var checks []*consulapi.HealthCheck var meta *consulapi.QueryMeta var err error @@ -207,6 +213,7 @@ func eventWatch(params map[string]interface{}) (WatcherFunc, error) { fn := func(p *Plan) (uint64, interface{}, error) { event := p.client.Event() opts := makeQueryOptionsWithContext(p, false) + defer p.cancelFunc() events, meta, err := event.List(name, &opts) if err != nil { return 0, nil, err diff --git a/watch/watch.go b/watch/watch.go index e04614620..bfc33628a 100644 --- a/watch/watch.go +++ b/watch/watch.go @@ -1,12 +1,11 @@ package watch import ( + "context" "fmt" "io" "sync" - "context" - consulapi "github.com/hashicorp/consul/api" )