[Tarantool-patches] [PATCH v2] fio: fix race condition in mktree

HustonMmmavr huston.mavr at gmail.com
Mon Jan 13 15:14:49 MSK 2020


Despite the lack of documentation, fio.mktree() was designed to work
similar to mkdir -p: it creates the directory along with it's parents
and doesn't complain about existing ones.

But this function was subject to a race if two different processes were
trying to create the same directory at the same time. It was caused by
the fact that directory existence check and its creation aren't atomic.

This patch fixes the race by impoving error handling: it's not an error
if directory exists, even if it was created by someone else and mktree
failed.

Related to https://github.com/tarantool/doc/issues/1063
Closes #4660
---
branch: https://github.com/tarantool/tarantool/tree/HustonMmmavr/gh-4660-fix-fio-mktree-race

 src/lua/fio.lua | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lua/fio.lua b/src/lua/fio.lua
index cb224f3d0..c9aeac951 100644
--- a/src/lua/fio.lua
+++ b/src/lua/fio.lua
@@ -364,7 +364,7 @@ fio.mktree = function(path, mode)
         local stat = fio.stat(current_dir)
         if stat == nil then
             local st, err = fio.mkdir(current_dir, mode)
-            if err ~= nil  then
+            if err ~= nil and not fio.path.is_dir(current_dir) then
                 return false, string.format("Error creating directory %s: %s",
                     current_dir, tostring(err))
             end
-- 
2.23.0



More information about the Tarantool-patches mailing list