]> git.ipfire.org Git - thirdparty/ccache.git/commit
fix: Avoid race condition in inode cache for quick updates
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 17 Nov 2022 20:31:58 +0000 (21:31 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 20 Nov 2022 20:44:24 +0000 (21:44 +0100)
commit3b6c2a5a63e104ed2090ddebe611182297fd1f9c
treebd51cf63a419900e8ba9ff711f9fba8874336b79
parentec77044ea62bab253e62ee5aaf2646a2ee551004
fix: Avoid race condition in inode cache for quick updates

The inode cache has a race condition that consists of these events:

1. A file is written with content C1, size S and timestamp (ctime/mtime)
   T.
2. Ccache hashes the file content and asks the inode cache to store the
   digest with a hash of S and T (and some other data) as the key.
3. The file is quickly thereafter written with content C2 without
   changing size S and timestamp T. The timestamp is not updated since
   the file writes are made within a time interval smaller than the
   granularity of the clock used for file system timestamps. At the time
   of writing, a common granularity on a Linux system is 0.004 s (250
   Hz).
4. The inode cache is asked for the file digest and the inode cache
   delivers a digest of C1 even though the file's content is C2.

To avoid the race condition, the inode cache now only caches inodes
whose timestamp was updated more than two seconds ago. This conservative
value is chosen since not all file systems have subsecond resolution.

Fixes #1215.
src/InodeCache.cpp
src/InodeCache.hpp
test/suites/inode_cache.bash
unittest/test_InodeCache.cpp