From 393bf4dbcbcb73e2f063088223126a79bead9af9 Mon Sep 17 00:00:00 2001 From: jessetang <1430482733@qq.com> Date: Sun, 26 Mar 2023 22:52:21 +0800 Subject: [PATCH] fix(contrib/registry/servicecomb): wrong stop ticker (#2749) Co-authored-by: haiyux --- contrib/registry/servicecomb/registry.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/contrib/registry/servicecomb/registry.go b/contrib/registry/servicecomb/registry.go index 3e2a0e9f9..d2e9a853e 100644 --- a/contrib/registry/servicecomb/registry.go +++ b/contrib/registry/servicecomb/registry.go @@ -124,9 +124,6 @@ func (r *Registry) Register(_ context.Context, svcIns *registry.ServiceInstance) // 保存当前版本微服务对应的sid curServiceID = sid } - props := make(map[string]string) - props[appIDKey] = appID - props[envKey] = env if svcIns.ID == "" { var id uuid.UUID id, err = uuid.NewV4() @@ -135,6 +132,10 @@ func (r *Registry) Register(_ context.Context, svcIns *registry.ServiceInstance) } svcIns.ID = id.String() } + props := map[string]string{ + appIDKey: appID, + envKey: env, + } _, err = r.cli.RegisterMicroServiceInstance(&discovery.MicroServiceInstance{ InstanceId: svcIns.ID, ServiceId: sid, @@ -146,9 +147,9 @@ func (r *Registry) Register(_ context.Context, svcIns *registry.ServiceInstance) if err != nil { return err } - ticker := time.NewTicker(30 * time.Second) - defer ticker.Stop() go func() { + ticker := time.NewTicker(30 * time.Second) + defer ticker.Stop() for { <-ticker.C _, err = r.cli.Heartbeat(sid, svcIns.ID)