1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-01-17 17:44:30 +02:00

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 <shuaihu.liu@shopee.com>
This commit is contained in:
littlecoderonway 2024-07-02 16:30:51 +08:00 committed by GitHub
parent e9ceb66e32
commit 4d5b3b084f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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