Repository navigation
Description
Tree.Move in posixfs reads the tree size of a moved folder without holding the folder's lock. A size change that propagates up through the folder at the same time can be counted twice in the new parent, or left in the old one.
How it happens
The sync propagator goes up one level at a time. At each level it locks the folder, adds the diff to its tree size, and reads its parent id. Then it goes on to that parent.
On main, Tree.Move takes no lock on the moved folder. It renames the folder, writes the new parent id, reads the folder's tree size s, and moves s from the old parent to the new one. A file in the folder grows by d at the same time:
- The propagator updates the folder after the parent id is written but before
Movereads the size. It reads the new parent id and addsdto the new parent.Movealso movess + d. The new parent countsdtwice, and the old parent losesdthat it never got. - The propagator reads the old parent id before the write but updates the folder after
Movereads the size. It addsdto the old parent.Movemoves onlys. The old parent keepsd, and the new parent never gets it.
Fix
Read the size while holding the folder's lock, in the same section as the rename and the parent id write. Then every propagation step on the folder is either finished before the move, so it is in the size and went to the old parent, or it starts after it and goes to the new parent.
#853 already holds the lock from the rename to the parent id write. That closes the second case. It still reads the size after the unlock, so the first case stays open. Moving the read up a few lines fixes it. I left it out of #853 to keep that PR small. I can add it there or open a separate PR, whichever you prefer.
With the xattrs metadata backend, the lock file is <path>.mlock, so the lock goes by path. Until the id cache is updated, the propagator locks the folder at its old path, and Move locks the new path, so they don't exclude each other. The default hybrid backend locks by id and doesn't have this problem.
I found this by reading the code, not in a test run. It needs a propagation and a move of the same folder within a few milliseconds of each other.
Activity
fix(posix): read the size of a moved item under its lock
NickWalters commentedon Oct 19, 2026
Fixed in #853 (38a42e6):
Tree.Movenow reads the size while it still holds the lock, from the metadata backend. A new spec covers it. This closes when #853 merges.