Conversation
JsonCacheInfoRepository writes through a temp file and renames it over the cache info file. Windows refuses that rename while another process holds either file open without delete sharing, which antivirus and the search indexer routinely do just after a file is written, so the write failed with ERROR_SHARING_VIOLATION and stayed pending until the next change. The rename is now retried a few times, about 750ms in all, when it fails with ERROR_SHARING_VIOLATION (32) or ERROR_ACCESS_DENIED (5).
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 kind of change does this PR introduce? (Bug fix, feature, docs update...)
Bug fix.
On Windows,
JsonCacheInfoRepository's atomic write (temp file + rename, since 3.4.3) fails withPathAccessException: Cannot rename file ... (OS Error: The process cannot access the file because it is being used by another process, errno = 32)whenever another process has the cache info file or the fresh temp file open without delete sharing. Antivirus and the search indexer routinely do that just after a file is written. The write is reported throughFlutterErrorand stays pending until the next change, so it's lost if the app exits first. We see this in production at app startup.🆕 What is the new behavior (if this is a feature change)?
When the rename fails with
ERROR_SHARING_VIOLATION(32) orERROR_ACCESS_DENIED(5), it's retried four times, with pauses of 50, 100, 200 and 400 ms (about 750 ms in all), before the failure is reported as before. Other errors are not retried.💥 Does this PR introduce a breaking change?
No
🐛 Recommendations for testing
New tests use a forwarding file system whose rename fails a set number of times: a refusal that clears is retried and persisted with no error reported, persistent refusals are reported after five attempts, and other error codes are not retried. The first two fail without the change.
flutter test,flutter analyzeanddart format --set-exit-if-changed .pass locally. Not run on a Windows machine with a real file lock.📝 Links to relevant issues/docs
MoveFileEx (used by
File.renameon Windows), system error codes.🤔 Checklist before submitting