From ac2cdce96c7180def817ee911b5ea1f23069c891 Mon Sep 17 00:00:00 2001 From: littlecoderonway Date: Tue, 2 Jul 2024 16:30:51 +0800 Subject: [PATCH] Fix registry cache broken (#2715) * services is shared between routines, when application change services returned by get function may lead to other routine set a changed services to cache * services is shared between routines, when application change services returned by get function may lead to other routine set a changed services to cache --------- Co-authored-by: Shuaihu Liu --- registry/cache/cache.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/registry/cache/cache.go b/registry/cache/cache.go index 9e25812560..7990b5a886 100644 --- a/registry/cache/cache.go +++ b/registry/cache/cache.go @@ -174,11 +174,12 @@ func (c *cache) get(service string) ([]*registry.Service, error) { } // cache results + cp := util.Copy(services) c.Lock() - c.set(service, util.Copy(services)) + c.set(service, services) c.Unlock() - return services, nil + return cp, nil } // watch service if not watched