Skip to content

Add opt-in persist-retry feature for transient rename failures - #445

Open
ChrisJr404 wants to merge 1 commit into
Stebalien:masterfrom
ChrisJr404:persist-retry
Open

ChrisJr404 wants to merge 1 commit into
Stebalien:masterfrom
ChrisJr404:persist-retry

Conversation

@ChrisJr404

Copy link
Copy Markdown

This adds the persist-retry feature we discussed in #316, so that persist and persist_noclobber retry the underlying rename when it fails with a transient error instead of failing on the first attempt.

The motivating case is Windows, where antivirus and file-indexing software briefly lock a file and make the rename fail with a sharing violation or access-denied error. When the feature is enabled, those errors are retried with an exponential backoff bounded to roughly a second (the same ballpark as graceful-fs, which was the prior art in the issue). Following your guidance on the issue, it's a feature flag that's off by default, it doesn't add a new method or any platform-specific API, and it adds no sleeps unless a caller opts in.

The retry loop is factored so the sleep is injectable, which keeps the behavior unit-testable without actually sleeping in the test suite. I ran the retry logic against the x86_64-pc-windows-msvc target as well to make sure the sharing-violation path type-checks. Retries are keyed off PermissionDenied (which ERROR_ACCESS_DENIED maps to) plus the raw ERROR_SHARING_VIOLATION code on Windows.

Closes #316.

Persisting a temporary file can fail transiently on Windows when
antivirus or file-indexing software briefly locks the file, causing the
rename to fail with a sharing violation or access-denied error. Add a
`persist-retry` feature that retries `persist` and `persist_noclobber`
with a short, bounded backoff on those errors. It is disabled by default
and does not change behavior when off.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement a persist_with_retry feature, enabling more resiliency on Windows

1 participant