From 8697ef327dac7cc50f90b889a483fc4e9006149b Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Thu, 27 May 2021 18:49:20 +0200 Subject: Fixed logic to avoid a race condition which could cause a sharing violation when two threads try to write the same chunk --- zenstore/filecas.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp index 4f5cf370e..64fcb2ffe 100644 --- a/zenstore/filecas.cpp +++ b/zenstore/filecas.cpp @@ -242,6 +242,10 @@ FileCasStrategy::InsertChunk(const void* const ChunkData, const size_t ChunkSize ChunkRemain -= ByteCount; } + // We cannot rely on RAII to close the file handle since it would be closed + // *after* the lock is released due to the initialization order. + PayloadFile.Close(); + AtomicIncrement(m_Stats.PutCount); AtomicAdd(m_Stats.PutBytes, ChunkSize); -- cgit v1.2.3