Repository navigation
Do not fail when multiple processes download the same lfs file - #3813
Merged
bk2204 merged 1 commit intoSep 10, 2019
Merged
Conversation
Contributor
Author
|
cicleci failure is not related to my changes. |
bk2204
requested changes
Sep 9, 2019
bk2204
left a comment
Member
There was a problem hiding this comment.
I think this looks like a fine fix from a high level perspective, but I'd like to see a slight change in the details.
When several git-lfs processes use the same LFS storage simultaneously, there's a race condition between checking whether LFS file exists and renaming temporary file to final name in LFS storage. When rename fails, check that target file exists. If it does, pretend that download has finished successfully. Fixes git-lfs#2825
slonopotamus
force-pushed
the
download-rename-race-condition
branch
from
September 10, 2019 10:05
150412b to
01bc6a6
Compare
Contributor
Author
|
Rebased onto fresh master to fix circleci breakage. |
bk2204
approved these changes
Sep 10, 2019
bk2204
left a comment
Member
There was a problem hiding this comment.
We lack a good way to verify that this is a sharing violation, so I think it's fine to leave this as it is.
slonopotamus
added a commit
to slonopotamus/git-lfs
that referenced
this pull request
Sep 19, 2019
1. git-lfs now only writes to unique temp files created with `ioutil.TempFile` that are open with `O_CREATE|O_EXCL` 2. Partially-downloaded file is now atomically borrowed and returned back via `os.Rename` 3. `.part <-> .tmp` and `.tmp -> final` renames are allowed to fail and are handled appropriately This is a continuation of git-lfs#3813 Fixes git-lfs#2825 There are several error codepaths where we borrow .part file but remove it instead of returning back. I believe that it is OK and in those erroneous cases it is better to restart download from scratch instead of attempting to use possibly-corrupt .part file.
slonopotamus
added a commit
to slonopotamus/git-lfs
that referenced
this pull request
Sep 19, 2019
1. git-lfs now only writes to unique temp files created with `ioutil.TempFile` that are open with `O_CREATE|O_EXCL` 2. Partially-downloaded file is now atomically borrowed and returned back via `os.Rename` 3. `.part <-> .tmp` and `.tmp -> final` renames are allowed to fail and are handled appropriately This is a continuation of git-lfs#3813 Fixes git-lfs#2825 There are several error codepaths where we borrow .part file but remove it instead of returning back. I believe that it is OK and in those erroneous cases it is better to restart download from scratch instead of attempting to use possibly-corrupt .part file.
slonopotamus
added a commit
to slonopotamus/git-lfs
that referenced
this pull request
Sep 23, 2019
1. git-lfs now only writes to unique temp files created with `ioutil.TempFile` that are open with `O_CREATE|O_EXCL` 2. Partially-downloaded file is now atomically borrowed and returned back via `os.Rename` 3. `.part <-> .tmp` and `.tmp -> final` renames are allowed to fail and are handled appropriately This is a continuation of git-lfs#3813 Fixes git-lfs#2825 There are several error codepaths where we borrow .part file but remove it instead of returning back. I believe that it is OK and in those erroneous cases it is better to restart download from scratch instead of attempting to use possibly-corrupt .part file.
slonopotamus
added a commit
to slonopotamus/git-lfs
that referenced
this pull request
Sep 26, 2019
1. git-lfs now only writes to unique temp files created with `ioutil.TempFile` that are open with `O_CREATE|O_EXCL` 2. Partially-downloaded file is now atomically borrowed and returned back via `os.Rename` 3. `.part <-> .tmp` and `.tmp -> final` renames are allowed to fail and are handled appropriately This is a continuation of git-lfs#3813 Fixes git-lfs#2825 There are several error codepaths where we borrow .part file but remove it instead of returning back. I believe that it is OK and in those erroneous cases it is better to restart download from scratch instead of attempting to use possibly-corrupt .part file.
slonopotamus
added a commit
to slonopotamus/git-lfs
that referenced
this pull request
Oct 23, 2019
On Windows, there is no way to replace file atomically. Instead, MoveFileExA: 1. Calls CreateFileA(access=Delete, shareMode=Delete) 2. Calls SetRenameInformationFile to rename file 3. Calls CloseFile The problem is that if parallel process attempts to read destination file between steps 2 and 3, it will try to do that without shareMode=Delete and will hit a SHARING_VIOLATION error. There are two solutions here: 1. Do not overwrite file if it already exists 2. Retry reading from file if got a SHARING_VIOLATION 3. Do not use Windows This commit implements option 1. Fixes git-lfs#2825 (again). Also see git-lfs#3813 and git-lfs#3826.
slonopotamus
added a commit
to slonopotamus/git-lfs
that referenced
this pull request
Oct 23, 2019
On Windows, there is no way to replace file atomically. Instead, MoveFileExA: 1. Calls CreateFileA(access=Delete, shareMode=Delete) 2. Calls SetRenameInformationFile to rename file 3. Calls CloseFile The problem is that if parallel process attempts to read destination file between steps 2 and 3, it will try to do that without shareMode=Delete and will hit a SHARING_VIOLATION error. There are two solutions here: 1. Do not overwrite file if it already exists 2. Retry reading from file if got a SHARING_VIOLATION 3. Do not use Windows This commit implements option 1. Fixes git-lfs#2825 (again). Also see git-lfs#3813 and git-lfs#3826.
slonopotamus
added a commit
to slonopotamus/git-lfs
that referenced
this pull request
Oct 23, 2019
On Windows, there is no way to replace file atomically. Instead, MoveFileExA: 1. Calls CreateFileA(access=Delete, shareMode=Delete) 2. Calls SetRenameInformationFile to rename file 3. Calls CloseFile The problem is that if parallel process attempts to read destination file between steps 2 and 3, it will try to do that without shareMode=Delete and will hit a SHARING_VIOLATION error. There are two solutions here: 1. Do not overwrite file if it already exists 2. Retry reading from file if got a SHARING_VIOLATION 3. Do not use Windows This commit implements option 1. Fixes git-lfs#2825 (again). Also see git-lfs#3813 and git-lfs#3826.
slonopotamus
added a commit
to slonopotamus/git-lfs
that referenced
this pull request
Oct 23, 2019
On Windows, there is no way to replace file atomically. Instead, MoveFileExA: 1. Calls CreateFileA(access=Delete, shareMode=Delete) 2. Calls SetRenameInformationFile to rename file 3. Calls CloseFile The problem is that if parallel process attempts to read destination file between steps 2 and 3, it will try to do that without shareMode=Delete and will hit a SHARING_VIOLATION error. There are two solutions here: 1. Do not overwrite file if it already exists 2. Retry reading from file if got a SHARING_VIOLATION 3. Do not use Windows This commit implements option 1. Fixes git-lfs#2825 (again). Also see git-lfs#3813 and git-lfs#3826.
slonopotamus
added a commit
to slonopotamus/git-lfs
that referenced
this pull request
Oct 25, 2019
…y on Windows On Windows, there is no way to replace file atomically. Instead, MoveFileExA: 1. Calls CreateFileA(access=Delete, shareMode=Delete) 2. Calls SetRenameInformationFile to rename file 3. Calls CloseFile The problem is that if parallel process attempts to open destination file for reading between steps 2 and 3, it will try to do that without shareMode=Delete and will hit a SHARING_VIOLATION error. In practice, this race condition results in: Smudge error: Error opening media file.: open .git\lfs\objects\<sha>: The process cannot access the file because it is being used by another process. There are two solutions here: 1. Do not overwrite file if it already exists 2. Retry reading from file if got a SHARING_VIOLATION This commit implements option 1. Fixes git-lfs#2825 (for Windows, other OSes are race-free already). Also see git-lfs#3813 and git-lfs#3826.
slonopotamus
added a commit
to slonopotamus/git-lfs
that referenced
this pull request
Oct 25, 2019
…y on Windows On Windows, there is no way to replace file atomically. Instead, MoveFileExA: 1. Calls CreateFileA(access=Delete, shareMode=Delete) 2. Calls SetRenameInformationFile to rename file 3. Calls CloseFile The problem is that if parallel process attempts to open destination file for reading between steps 2 and 3, it will try to do that without shareMode=Delete and will hit a SHARING_VIOLATION error. In practice, this race condition results in: Smudge error: Error opening media file.: open .git\lfs\objects\<sha>: The process cannot access the file because it is being used by another process. There are two solutions here: 1. Do not overwrite file if it already exists 2. Retry reading from file if got a SHARING_VIOLATION This commit implements option 1. Fixes git-lfs#2825 (for Windows, other OSes are race-free already). Also see git-lfs#3813 and git-lfs#3826.
slonopotamus
added a commit
to slonopotamus/git-lfs
that referenced
this pull request
Oct 25, 2019
…y on Windows On Windows, there is no way to replace file atomically. Instead, MoveFileExA: 1. Calls CreateFileA(access=Delete, shareMode=Delete) 2. Calls SetRenameInformationFile to rename file 3. Calls CloseFile The problem is that if parallel process attempts to open destination file for reading between steps 2 and 3, it will try to do that without shareMode=Delete and will hit a SHARING_VIOLATION error. In practice, this race condition results in: Smudge error: Error opening media file.: open .git\lfs\objects\<sha>: The process cannot access the file because it is being used by another process. There are two solutions here: 1. Do not overwrite file if it already exists 2. Retry reading from file if got a SHARING_VIOLATION This commit implements option 1. Fixes git-lfs#2825 (for Windows, other OSes are race-free already). Also see git-lfs#3813 and git-lfs#3826.
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.
When several git-lfs processes use the same LFS storage simultaneously,
there's a race condition between checking whether LFS file exists and renaming temporary
file to final name in LFS storage. When rename fails, check that target file exists.
If it does, pretend that download has finished successfully.
Fixes #2825
I'm not sure how to write a test for this.