From fd047227065e4e635942b7a2ec81f5545b6b9ccc Mon Sep 17 00:00:00 2001 From: lovelly <840635577@qq.com> Date: Tue, 9 Oct 2018 10:40:24 +0800 Subject: [PATCH] Fix tcp check no ttl error --- registry/consul_registry.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/registry/consul_registry.go b/registry/consul_registry.go index e8de9ead..6540c2a7 100644 --- a/registry/consul_registry.go +++ b/registry/consul_registry.go @@ -180,10 +180,21 @@ func (c *consulRegistry) Register(s *Service, opts ...RegisterOption) error { // if it's already registered and matches then just pass the check if ok && v == h { - // if the err is nil we're all good, bail out - // if not, we don't know what the state is, so full re-register - if err := c.Client.Agent().PassTTL("service:"+node.Id, ""); err == nil { - return nil + if options.TTL == time.Duration(0) { + services,_, err := c.Client.Health().Checks(s.Name, nil) + if err == nil { + for _, v := range services { + if v.ServiceID == node.Id { + return nil + } + } + } + }else{ + // if the err is nil we're all good, bail out + // if not, we don't know what the state is, so full re-register + if err := c.Client.Agent().PassTTL("service:"+node.Id, ""); err == nil { + return nil + } } }