Skip to content

Commit

Permalink
Async-cache a map copy for thread-safety reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck authored and butonic committed Jul 6, 2023
1 parent 9cbac03 commit 38d0c09
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,12 @@ func (b MessagePackBackend) loadAttributes(ctx context.Context, path string, sou
}
}

go func() { _ = b.metaCache.PushToCache(b.cacheKey(path), attribs) }()
// Prepare a copy to push to cache. Pushing the original map isn't thread-safe
attribsCopy := map[string][]byte{}
for k, v := range attribs {
attribsCopy[k] = v
}
go func() { _ = b.metaCache.PushToCache(b.cacheKey(path), attribsCopy) }()

return attribs, nil
}
Expand Down

0 comments on commit 38d0c09

Please sign in to comment.