Repository navigation
Commit 6378aa8
committed
S4b (Zoo-Code-Org#1375): create the directory the lock needs before taking the lock
proper-lockfile creates the lock artefact with a non-recursive mkdir. A guarded write into
a directory that did not exist yet therefore failed inside acquireFileLock with ENOENT -
before the publish primitive ran, and so before the rollback the publish owns could do
anything about it - and left the empty tree behind for DiffViewProvider.ts:1843-:1845 and
safeWriteText.ts:437-:443 to defend against. The directory the artefact needs is now
created first, and the artefact itself is still derived only from the guarded path.
The empirical answer on the alternative, measured on a real temporary tree rather than
argued: writer A took <existing-dir>.lock, created the missing parent under it, and writer
B - arriving after the parent existed, for the file A was about to write - acquired
<existing-dir>/nested/state.json.lock while A still held its lock. Those are different
locations, so B did not contend at all. Widening the lock to an ancestor means the
artefact depends on what happens to exist at the moment each writer derives it, which is
the divergence class the repair exists to close. With the shipped derivation the same late
writer is refused: 'Lock file is already being held'. That is why the mkdir moved before
the lock rather than the lock moving to the ancestor.
'Only the directories this call created' is answered by asking the filesystem to create and
reading the answer, not by statting: recursive mkdir resolves with the first directory it
actually made, and with nothing when every level already existed. Measured on this host,
that answer arrives with an extended-length prefix (\\?\C:\...); comparing it with the
chain unnormalised made a rollback climb past the tree it had built and remove directories
that were already there. It is normalised before it is compared, the rollback runs deepest-
first and swallows its own failures, and the acquisition error reaches the caller unchanged.
The first version of this walked the chain with fs.stat, and that was wrong for a reason I
only found by running the neighbours: it reddened two safeWriteJson rows, including
safeWriteJson.stagingDirectory.spec.ts's 'stages anyway under the task persistence suite's
blanket missing stat', whose whole point is that a write must not start asking fs.stat
questions about the directory it is allowed to write into - the task-persistence suites
mock fs.stat to reject for every path. The create-shape asks no such question and both rows
are green again. There is deliberately no fs.stat call in the chain builder.
Rows: fileLock.test.ts 2 (the parent exists before the lock is taken and the artefact stayed
at lockPathFor(path); a failed acquisition gives back only what it created, and a directory
that already existed survives it). fileLockContention.test.ts 2, against the real
proper-lockfile on real directories (a writer arriving after the directory exists contends
with the writer that created it; two writers racing into the same missing directory leave
exactly one holding the path, the loser refused with 'already being held', and no lock
artefact leaks). fileLockChain.test.ts 2, where the doubles hold Node's recursive-mkdir
contract and the assertions read the calls: nothing is claimed when nothing was created, and
only the reported levels are given back, deepest first.
Controls, each failing only for the reason its row describes: skipping the create fails the
two creation rows and both contention rows ('ENOENT ... mkdir <file>.lock', 'expected [] to
have a length of 1'); claiming something even when the create reported nothing fails the
nothing-claimed row alone ('expected vi.fn() to not be called at all, but actually been
called 1 times'); claiming one level above what was created fails both only-what-it-created
rows ('ENOENT ... stat <existing>/one'); keeping what was created fails the two rollback
rows; moving the artefact to the parent directory fails both contention rows and the
artefact-location assertion, and also the pre-existing drift-guard row, which is right to
fail when the artefact stops being lockPathFor(path); comparing the create's answer without
normalising it fails the claim row alone. The control that reports the rollback instead of
the acquisition failure reddens six rows rather than one, because it changes the identity of
every acquisition failure - the two rollback rows and the claim rows are the ones that name
it, and one pre-existing safeWriteJson row reports it too; stated rather than hidden.
Lanes: fileLock 4, contention 2, chain 2, safeWriteJson + stagingDirectory + lockKey 57
passed | 4 skipped, and the wide run over every utils/ and services/ lane is 190 files
passed | 11 failed - the same eleven that fail at HEAD fileLock.ts on this host (5 Windows
symlink EPERM rows in rules, 4 'TelemetryService not initialized' rows in MarketplaceManager,
2 rows in code-index parser), so nothing moved in either direction. DiffViewProvider 168 and
guardedWrite 73 green. eslint --max-warnings=0 exit 0 on all six touched files;
--prune-suppressions run afterwards and src/eslint-suppressions.json restored to HEAD and
verified by an empty diff (a narrow prune rewrites 1326 of 1326 lines and drops records for
files outside the selection, so it is a check and never a commit). prettier --check clean.
tsc --noEmit -p . shows only activate/registerCommands.ts(88,102) TS2739, the local junction
artifact. No it.runIf(win32) anywhere in the change: the rows run on every platform, and the
extended-length prefix is handled by normalising what Windows reports rather than by gating
a test.
Review row 4507646158.1 parent dec06df commit 6378aa8
4 files changed
Lines changed: 245 additions & 2 deletions
File tree
- src/utils
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
1 | 4 | | |
2 | 5 | | |
3 | 6 | | |
| |||
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
38 | 92 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
27 | 96 | | |
28 | 97 | | |
29 | 98 | | |
| |||
41 | 110 | | |
42 | 111 | | |
43 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
44 | 125 | | |
45 | 126 | | |
46 | 127 | | |
47 | 128 | | |
48 | | - | |
| 129 | + | |
49 | 130 | | |
50 | 131 | | |
51 | 132 | | |
| |||
68 | 149 | | |
69 | 150 | | |
70 | 151 | | |
71 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
72 | 156 | | |
73 | 157 | | |
74 | 158 | | |
| |||
0 commit comments