From 62f7e56a1828bd58051bc4d9b0ceeb1ccb8daa82 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 30 Jan 2023 19:00:00 +0200 Subject: [PATCH] v.vcache: fix a panic due to a race on creating folders in ~/.vmodules/cache/XY --- vlib/v/vcache/vcache.v | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vlib/v/vcache/vcache.v b/vlib/v/vcache/vcache.v index e2fe6f7d3..57d35361b 100644 --- a/vlib/v/vcache/vcache.v +++ b/vlib/v/vcache/vcache.v @@ -89,7 +89,13 @@ pub fn (mut cm CacheManager) key2cpath(key string) string { cprefix_folder := os.join_path(cm.basepath, prefix) cpath = os.join_path(cprefix_folder, khash) if !os.is_dir(cprefix_folder) { - os.mkdir_all(cprefix_folder) or { panic(err) } + os.mkdir_all(cprefix_folder) or { + // The error here may be due to a race with another independent V process, that has already created the same folder. + // If that is the case, so be it - just reuse the folder ¯\_(ツ)_/¯ ... + if !os.is_dir(cprefix_folder) { + panic(err) + } + } } dlog(@FN, 'new hk') dlog(@FN, ' key: ${key}') -- 2.30.2