Commit e3ada12
committed
fix(windows): retry ENOENT errors and add delays to prevent file access race conditions
Windows file operations are asynchronous at the OS level. After writeFile()
completes, the filesystem may not immediately make the file accessible, causing
ENOENT errors when attempting to read the file immediately after writing.
Root Cause Analysis:
The previous implementation only retried EPERM and EBUSY errors. However,
Windows frequently returns ENOENT during the window between when writeFile()
returns and when the file becomes accessible. This manifested as intermittent
test failures in Windows CI environments where filesystem operations are
particularly slow.
Solution:
1. **Add ENOENT to retriable error codes** - Critical fix that enables retry
on the actual error being thrown
2. Implement progressive retry strategy with increasing delays:
- Initial 50ms delay after write to allow OS flush
- Up to 5 access verification attempts with exponential backoff
(20ms, 40ms, 60ms, 80ms, 100ms)
- 10ms stabilization delay after successful access
- Maximum total wait: 360ms (50 + 300 + 10)
The delays are calibrated for Windows CI runners which exhibit significantly
slower filesystem operations than local development environments. The retry
logic provides resilience while the delays reduce the frequency of retries
needed.
Fixes intermittent Windows CI test failures including:
- "should use default 2-space indent for new files"
- "should handle load -> update -> save workflow"
- "should preserve line endings"
- "should support sort option"
- "should use LF line endings by default"
- "should handle save -> update -> save again"
Technical Details:
- Modified: src/json/edit.ts:51-100 (retryWrite function)
- Platform-specific: Windows only (process.platform === 'win32')
- No impact on non-Windows platforms1 parent 1fb817e commit e3ada12
1 file changed
+34
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
58 | 60 | | |
59 | 61 | | |
60 | 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 | + | |
61 | 90 | | |
62 | 91 | | |
63 | 92 | | |
64 | | - | |
| 93 | + | |
65 | 94 | | |
66 | 95 | | |
67 | | - | |
| 96 | + | |
68 | 97 | | |
69 | | - | |
70 | | - | |
| 98 | + | |
| 99 | + | |
71 | 100 | | |
72 | 101 | | |
73 | 102 | | |
74 | 103 | | |
75 | 104 | | |
76 | 105 | | |
77 | | - | |
| 106 | + | |
78 | 107 | | |
79 | 108 | | |
80 | 109 | | |
| |||
0 commit comments