storage: fix possible race condition with maps.Keys iterator (#5321)

This commit is contained in:
Joe Kralicky 2024-10-07 18:45:23 -04:00 committed by GitHub
parent 2aea633f80
commit 2f8743522d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -203,10 +203,10 @@ func (backend *Backend) Lease(_ context.Context, leaseName, leaseID string, ttl
// ListTypes lists the record types.
func (backend *Backend) ListTypes(_ context.Context) ([]string, error) {
backend.mu.Lock()
keys := maps.Keys(backend.lookup)
backend.mu.Unlock()
defer backend.mu.Unlock()
keys := slices.Sorted(maps.Keys(backend.lookup))
return slices.Sorted(keys), nil
return keys, nil
}
// Put puts a record into the in-memory store.