diff --git a/contrib/registry/consul/client.go b/contrib/registry/consul/client.go index ea5fe846d..ac51ca03c 100644 --- a/contrib/registry/consul/client.go +++ b/contrib/registry/consul/client.go @@ -204,6 +204,8 @@ func (c *Client) Register(_ context.Context, svc *registry.ServiceInstance, enab ticker := time.NewTicker(time.Second * time.Duration(c.healthcheckInterval)) defer ticker.Stop() for { + // NOTICE: the try-receive operation here is to try to exit the sender goroutine as early as possible. + // https://go101.org/article/channel-closing.html select { case <-c.ctx.Done(): _ = c.cli.Agent().ServiceDeregister(svc.ID) diff --git a/contrib/registry/consul/go.mod b/contrib/registry/consul/go.mod index 09616ae1b..6e9e388e9 100644 --- a/contrib/registry/consul/go.mod +++ b/contrib/registry/consul/go.mod @@ -3,10 +3,13 @@ module github.com/go-kratos/kratos/contrib/registry/consul/v2 go 1.16 require ( - github.com/armon/go-metrics v0.3.10 // indirect github.com/go-kratos/kratos/v2 v2.6.1 - github.com/google/btree v1.0.0 // indirect github.com/hashicorp/consul/api v1.19.1 +) + +require ( + github.com/google/btree v1.0.0 // indirect + github.com/armon/go-metrics v0.3.10 // indirect github.com/hashicorp/go-hclog v0.14.1 // indirect github.com/hashicorp/go-immutable-radix v1.3.0 // indirect github.com/hashicorp/go-msgpack v0.5.5 // indirect