From 457490403853321d308c6ca6aaa90d6f8f29b4cf Mon Sep 17 00:00:00 2001 From: Evan Klitzke Date: Thu, 15 Mar 2018 06:54:11 -0700 Subject: [PATCH] Fix possible data race when committing block files It was recently pointed out to me that calling fsync() or fdatasync() on a new file is not sufficient to ensure it's persisted to disk, a the existence of the file itself is stored in the directory inode. This means that ensuring that a new file is actually committed also requires an fsync() on the parent directory. This change ensures that we call fsync() on the blocks directory after committing new block files. --- src/flatfile.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/flatfile.cpp b/src/flatfile.cpp index 8a8f7b681c5..11cf357f3dd 100644 --- a/src/flatfile.cpp +++ b/src/flatfile.cpp @@ -92,6 +92,7 @@ bool FlatFileSeq::Flush(const FlatFilePos& pos, bool finalize) fclose(file); return error("%s: failed to commit file %d", __func__, pos.nFile); } + DirectoryCommit(m_dir); fclose(file); return true;