mirror of
https://github.com/moby/buildkit.git
synced 2026-10-28 16:44:37 +08:00
getRecord checked rec.isDead() holding only cm.mu, while finalize updates equalMutable and the mutable's dead flag under the record mutex, so a concurrent Get and Finalize of a lazily committed ref raced. Take the record mutex for the check; lock order stays cm.mu then record mutex, as in get(). Records restored from metadata also did not follow the rule that records sharing data share a mutex: the immutable got a new mutex instead of the equal mutable's, as mutableRef.commit does. Share it, so finalize and lookups of the mutable synchronize after a restart. Add tests for both cases; they report the races under -race without the fix. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>