Repository navigation
Retry the database open when Windows briefly denies access - #7
Merged
Merged
Conversation
Creating a LevelDB database renames a temp file to CURRENT. On Windows an antivirus scanning the new file can hold it for a moment and the rename fails with "Access is denied"; queued operations then only report "Database is not open", so npm test failed one random test on machines with real-time scanning. - state/db.ts: retryTransientOpen retries an open that failed with "Access is denied" / "being used by another process" (25 ms doubling to 800 ms, about 1.5 s in all); any other error is thrown at once, and after the last retry the real error is. Hooked into Level's _open, so operations queued behind the open simply wait. - node.ts: start() awaits the open and names the real cause when the data directory can't be opened. - Three tests (622 in total); docs and site say 622. Live-checked on Windows: a CURRENT rename blocked for 120 ms now opens; blocked for good, start() reports the RenameFile ... Access is denied error. The full suite from PowerShell passed 8 runs out of 8.
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.
What was wrong
Creating a LevelDB database writes a temp file and renames it to
CURRENT. On Windows, an antivirus scanning the new file can hold it for a moment, and the rename fails:abstract-level hides that error: operations queued behind the open only say
Database is not open. On a machine with real-time scanning (Sophos Home + Bitdefender here),npm testoften failed one random test this way.The fix
src/state/db.ts:retryTransientOpenretries an open that failed with "Access is denied" or "being used by another process" (25 ms, doubling to 800 ms; about 1.5 s in all). Any other error (corruption, a held LOCK, a bad path) is thrown at once, and after the last retry the real error is thrown. It's hooked into Level's_open, so queued operations just wait.src/node/node.ts:start()waits for the open and names the real cause if the data directory can't be opened.tests/state/db.test.ts(622 in total). README, docs and site updated to 622. CHANGELOG: Unreleased.No consensus or network change.
Checked
npm run typecheck,npm run build,npm test: 622 passed.CURRENTrename blocked for 120 ms, the open succeeds after a retry. Blocked for good,start()fails with theRenameFile … Access is deniedmessage.