From 4d5b3b084f901074778c1f9fdc7ea7943a549d39 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 33680ffbca..867ea079ae 100644 --- a/registry/cache/cache.go +++ b/registry/cache/cache.go @@ -161,11 +161,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