diff --git a/internal/core/src/storage/StorageV2FSCache.cpp b/internal/core/src/storage/StorageV2FSCache.cpp index d18fb670e4..c624b053d2 100644 --- a/internal/core/src/storage/StorageV2FSCache.cpp +++ b/internal/core/src/storage/StorageV2FSCache.cpp @@ -37,16 +37,21 @@ StorageV2FSCache::Get(const Key& key) { std::promise p; std::shared_future f = p.get_future(); + std::shared_lock lck(mutex_); auto [iter, inserted] = concurrent_map_.emplace(key, Value(std::move(p), f)); + lck.unlock(); + if (!inserted) { std::shared_lock lck(mutex_); - // double check: avoid iter has been earsed by other thread + // double check: avoid iter has been erased by other thread auto it = concurrent_map_.find(key); if (it != concurrent_map_.end()) { return it->second.second.get(); } - return nullptr; + lck.unlock(); + // retry if already delete + return Get(key); } try {