fix(windows): widen atomicWriteFile rename-retry backoff for EPERM/EACCES#1714
Open
kriszyp wants to merge 1 commit into
Open
fix(windows): widen atomicWriteFile rename-retry backoff for EPERM/EACCES#1714kriszyp wants to merge 1 commit into
kriszyp wants to merge 1 commit into
Conversation
…CCES The existing retry-on-EPERM/EACCES loop in atomicWriteFile only budgeted 5 retries x fixed 10ms (50ms total) - too tight for the actual race: every worker thread runs its own RootConfigWatcher (chokidar), which does an async readFile whenever the config file changes, so a write on one thread routinely races a hot-reload read on a sibling thread on Windows (no POSIX-style atomic-replace-open-file semantics), plus possible AV scanner interference. Widen to exponential backoff (8 retries, 10ms initial, doubling, capped at 200ms/attempt, ~910ms worst case), switch the busy-wait clock to performance.now() (monotonic, avoids a backward NTP jump turning the spin into an unbounded stall), and make the retry params injectable so tests can exercise the real default retry count without paying the real wall-clock cost. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
Contributor
|
Reviewed; no blockers found. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Widens the retry-on-EPERM/EACCES loop in
config/configUtils.ts'satomicWriteFile(the write-temp-file-then-rename helper used by every config write path:createConfigFile,checkForUpdatedConfig,updateConfigValue,addConfig,deleteConfigFromFile,applyRuntimeEnvVarConfig) from a 50ms total budget to exponential backoff (~910ms worst case), switches the busy-wait clock to a monotonic source, and makes the retry parameters injectable for fast unit tests.Root cause
Discovered incidentally while investigating an unrelated PR (#1713,
kris/hnsw-delete-ep-flake) — a Windows CI job failed with:Rerunning the same job passed clean, confirming a low-frequency flake rather than a deterministic break.
atomicWriteFilealready had a retry-on-EPERM/EACCES loop, added in a prior commit for this exact class of Windows issue ("atomic renames on Windows will throw EPERM if the target file is momentarily held open for reading by another process or thread"). That loop was under-budgeted: 5 retries × a fixed 10ms sleep = 50ms total.Windows has no POSIX-style "replace an open file" semantics —
rename()fails with EPERM/EACCES if the destination is momentarily open elsewhere. Every Harper worker thread runs its ownRootConfigWatcher(chokidar-based hot-reload watcher, seeconfig/RootConfigWatcher.ts), which does an asyncreadFileon the config file whenever it changes. A config write on one thread therefore routinely races a hot-reload read on a sibling thread; Windows Defender / AV real-time scanning can hold a similar transient handle. 50ms just isn't always enough for the reader to close its handle.Fix
Date.now()toperformance.now()— monotonic, so a backward wall-clock jump (e.g. NTP sync) can't turn the spin into an unbounded stall (caught in cross-model review).maxRetries/initialDelayMs/maxDelayMs, all defaulting to the production values) so unit tests can exercise the real default retry count without paying the real ~900ms wall-clock cost for the exhaustion path.Where to look / accepted tradeoffs
RootConfigWatcherreads / AV, which do ride out the wait). Worth being aware of if this flake recurs after this fix ships.Reviewed via cross-model review (thorough mode: Gemini + Codex legs + Harper-domain adjudication) — no blockers; the two items above are the adjudicated open callouts.
Generated with Claude Sonnet 5.