You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When multiple same modules share one lfs storage (by git config lfs.storage=STORAGE). Access from multiple instances with command 'git lfs fetch' fails. But it's expected to shared the storage.
Access from multiple instances with command 'git lfs fetch' fails.
Can you clarify the issue here? It is my understanding that if two processes (A) and (B) are using git-lfs-fetch(1) concurrently with a shared lfs.storage configuration, that they will both download the same large file, thus wasting energy?
If so, I think that this can be solved with a lock file in the same way that Git prevents multiple writes to the index at once. Something like:
Is this the issue that you're experiencing? If so, I think that this would be a wonderful contribution to LFS, and is something that I'd be happy to help someone out with.
The problem is, that git-lfs.exe is called from git.exe and it's not easy to recognize which git operation will invoke git-lfs. Locking is the solution, but every operation on repository must be locked because of lfs shared storage. This slows down the parallel checkout (or other operation).
For example:
process (A) and (B). I have repository (X) and (Y), these repos contains submodules (K), (L) and (M), where
(X)->(K), (L)
(Y)->(K), (L), (M)
parallel execution of git recursive fetch (could be reset(invoke git-lfs fetch), checkout):
(A) git fetch -> (X)
(B) git fetch -> (Y)
is ok, because thay have no shared storage and recursive submodules has it's own storage space. parallel processing is valid without any sharing violation.
But when I add shared lfs storage, I get multiple sharing violation errors. Locking is safe but i need to lock every git operation, which slows down all git operations (git-lfs fetch is invoked by git and i'm not able to decide if I need to lock the shared storage or not, it's possible to decide, but it's not so eazy).
If there is shared storage available in git-lfs, is there possibility to add some locking (via lfs config) to avoid sis sharing violation.
This is and simple example, I have more than 30 repos with multiple list of submodules (the same) processed in parallel.
I tried to not use lfs storage, but git-lfs.exe deadock when used multiple instances at the same repo (same URL, different space). That's the reason I decide to use lfs.storage, but the result is sharing violation.
But when I add shared lfs storage, I get multiple sharing violation errors. Locking is safe but i need to lock every git operation, which slows down all git operations (git-lfs fetch is invoked by git and i'm not able to decide if I need to lock the shared storage or not, it's possible to decide, but it's not so eazy).
If there is shared storage available in git-lfs, is there possibility to add some locking (via lfs config) to avoid sis sharing violation.
Is the idea something like git config --bool lfs.lockstorage true to enable locking as an opt-in operation to not prevent slow-downs in other areas of operation?
I think that something like this would work and solve your problem, but I'm not sure if we should push forward in implementing this, since users can easily opt out (git config --bool lfs.lockstorage false) and the race condition re-appears.
Yes, git config --bool lfs.lockstorage true could be the slolution. Because now there is no way to do that.
If someone sets lfs.lockstorage false together with lfs.storage, he should know what he is doing (the false value could be default).
I am strongly against locking approach, because it will
Force serial access even in cases where nothing needed to be downloaded
Will definitely produce situations when lock file got stuck because git-lfs was hard-killed or something like that
Instead, my suggestion is: if git-lfs suddenly detected that file that it was downloading is already downloaded, just silently pretend that everything is OK. See #3813 that attempts to implement this strategy.
There's one more race: for incomplete files, git-lfs uses deterministic file names (actually, just object hash). So, it is possible for os.Rename to fail because source file is currently open by concurrent process.
@bk2204 Please, reopen this issue. I'm working on a new PR.
There's a race between os.OpenFile(..., O_RDWR, ...) and os.OpenFile(..., os.O_CREATE|os.O_WRONLY|os.O_EXCL, ...) in basicDownloadAdapter.checkResumeDownload on any OS.
Multiple processes can os.OpenFile(..., O_RDWR, ...) in basicDownloadAdapter.checkResumeDownload, it is not exclusive and doesn't lock anything except moving/deleting file on Windows, even though comment in code says the different thing. This in fact happens to us, multiple processes open the same temp file and simultaneously write to it. On Windows, all git-lfs processes except the last one fail because they cannot rename temp file. On POSIX systems, all git-lfs processes except the first one failed before Do not fail when multiple processes download the same lfs file #3813. After Do not fail when multiple processes download the same lfs file #3813, POSIX systems no longer fail here but Windows still does.
os.Remove calls in basicDownloadAdapter.download are not checked for success. On Windows, it means that file might not be deleted, but later opened with os.O_WRONLY|os.O_CREATE|os.O_TRUNC. I'm not sure how O_TRUNK operates when other process already has the same file in write mode.
If there was no download resuming, fixing all this stuff would be trivial: just download file under random temp name then move. If move failed but target file exists, pretend everything is fine (this is what Do not fail when multiple processes download the same lfs file #3813 did). But removal of download resuming is not an option, right? @bk2204
With resuming of downloads, things become now we need to share half-downloaded file somehow.
2.1. Cheap and temporary solution: add config option that allows to opt-out from resuming of downloads but fixes concurrency.
2.2. Use smth like gofrs/flock to make sure that only a single process operates on a file
2.3. Guard operations with half-downloaded files with os.Rename: writes only happen when file has random temp name. At the start of download, an attempt to os.Rename("<sha>.tmp", "<random>") is made. If rename is successful, we've successfully stole partially downloaded file and can resume download. If rename isn't successful, we download the whole file. If we fail in the middle of download (broken network, CTRL+C, etc), we os.Rename("<random>", "<sha>.tmp") so we can resume download next time. In case of hard fail (SIGKILL, poweroff) we won't be able to resume download, though this doesn't look like a big problem. To be honest, I haven't heard of any software that works this way.
2.4. Introduce a huge lock file (like .git/index.lock) that will guard all write operations to LFS storage. Ideally, this lock should be even more complex because in git-lfs there are three types of operations - read, fetch and prune. However, like with .git/index.lock, such thing will cause pains because it will from time to time get stuck.
I also want to note that this issue is not specific to shared lfs.storage across several working copies. It is also possible to trigger multiple git-lfs processes working on the same file even with a single working copy, for example by running several git show <commit-ish>:<path/to/lfs/file> at the same time
Removal of download resuming is not an option. Folks in many parts of the world have unreliable connections, and even people who usually have good connections sometimes get on airplanes where the WiFi is bad.
We definitely need some sort of locking here. Unfortunately, flock is not a viable choice because it doesn't work on NFS, and I'm sure we have folks using NFS. That means that we need to use fcntl locking or dotlocking (using the algorithm specified in Linux's open(2) manpage under O_EXCL) and, if we're using fcntl locking, avoid opening multiple file descriptors to the same file. I have no clue which if any of these will work on Windows, though.
Adopting the same algorithm Git uses when writing refs for use when we're writing objects sounds like a reasonable plan; we know it's generally reliable and we know it works on NFS. Since we may not want to rewrite the object to the side and rename over it, it sounds like this is describing option 2.3, which could be reasonable.
Activity
ttaylorr commentedon Jan 20, 2018
Can you clarify the issue here? It is my understanding that if two processes (A) and (B) are using
git-lfs-fetch(1)concurrently with a sharedlfs.storageconfiguration, that they will both download the same large file, thus wasting energy?If so, I think that this can be solved with a lock file in the same way that Git prevents multiple writes to the index at once. Something like:
Is this the issue that you're experiencing? If so, I think that this would be a wonderful contribution to LFS, and is something that I'd be happy to help someone out with.
yodovicz commentedon Jan 22, 2018
The problem is, that git-lfs.exe is called from git.exe and it's not easy to recognize which git operation will invoke git-lfs. Locking is the solution, but every operation on repository must be locked because of lfs shared storage. This slows down the parallel checkout (or other operation).
For example:
process (A) and (B). I have repository (X) and (Y), these repos contains submodules (K), (L) and (M), where
(X)->(K), (L)
(Y)->(K), (L), (M)
parallel execution of git recursive fetch (could be reset(invoke git-lfs fetch), checkout):
(A) git fetch -> (X)
(B) git fetch -> (Y)
is ok, because thay have no shared storage and recursive submodules has it's own storage space. parallel processing is valid without any sharing violation.
But when I add shared lfs storage, I get multiple sharing violation errors. Locking is safe but i need to lock every git operation, which slows down all git operations (git-lfs fetch is invoked by git and i'm not able to decide if I need to lock the shared storage or not, it's possible to decide, but it's not so eazy).
If there is shared storage available in git-lfs, is there possibility to add some locking (via lfs config) to avoid sis sharing violation.
This is and simple example, I have more than 30 repos with multiple list of submodules (the same) processed in parallel.
I tried to not use lfs storage, but git-lfs.exe deadock when used multiple instances at the same repo (same URL, different space). That's the reason I decide to use lfs.storage, but the result is sharing violation.
ttaylorr commentedon Jan 31, 2018
Is the idea something like
git config --bool lfs.lockstorage trueto enable locking as an opt-in operation to not prevent slow-downs in other areas of operation?I think that something like this would work and solve your problem, but I'm not sure if we should push forward in implementing this, since users can easily opt out (
git config --bool lfs.lockstorage false) and the race condition re-appears.yodovicz commentedon Feb 1, 2018
Yes, git config --bool lfs.lockstorage true could be the slolution. Because now there is no way to do that.
If someone sets lfs.lockstorage false together with lfs.storage, he should know what he is doing (the false value could be default).
Do not fail when multiple processes download the same lfs file
slonopotamus commentedon Sep 9, 2019
I am strongly against locking approach, because it will
Instead, my suggestion is: if git-lfs suddenly detected that file that it was downloading is already downloaded, just silently pretend that everything is OK. See #3813 that attempts to implement this strategy.
Do not fail when multiple processes download the same lfs file
slonopotamus commentedon Sep 18, 2019
My fix in #3813 is a good thing, but not enough.
There's one more race: for incomplete files, git-lfs uses deterministic file names (actually, just object hash). So, it is possible for
os.Renameto fail because source file is currently open by concurrent process.@bk2204 Please, reopen this issue. I'm working on a new PR.
slonopotamus commentedon Sep 18, 2019
A (somewhat) full problem analysis:
os.OpenFile(..., O_RDWR, ...)andos.OpenFile(..., os.O_CREATE|os.O_WRONLY|os.O_EXCL, ...)inbasicDownloadAdapter.checkResumeDownloadon any OS.os.OpenFile(..., O_RDWR, ...)inbasicDownloadAdapter.checkResumeDownload, it is not exclusive and doesn't lock anything except moving/deleting file on Windows, even though comment in code says the different thing. This in fact happens to us, multiple processes open the same temp file and simultaneously write to it. On Windows, all git-lfs processes except the last one fail because they cannot rename temp file. On POSIX systems, all git-lfs processes except the first one failed before Do not fail when multiple processes download the same lfs file #3813. After Do not fail when multiple processes download the same lfs file #3813, POSIX systems no longer fail here but Windows still does.os.Removecalls inbasicDownloadAdapter.downloadare not checked for success. On Windows, it means that file might not be deleted, but later opened withos.O_WRONLY|os.O_CREATE|os.O_TRUNC. I'm not sure howO_TRUNKoperates when other process already has the same file in write mode.basicDownloadAdapter.downloadandtools.RenameFileCopyPermissions, Do not fail when multiple processes download the same lfs file #3813 covers it.tools.RenameFileCopyPermissions, Do not fail when multiple processes download the same lfs file #3813 covers them.Thoughts:
2.1. Cheap and temporary solution: add config option that allows to opt-out from resuming of downloads but fixes concurrency.
2.2. Use smth like gofrs/flock to make sure that only a single process operates on a file
2.3. Guard operations with half-downloaded files with
os.Rename: writes only happen when file has random temp name. At the start of download, an attempt toos.Rename("<sha>.tmp", "<random>")is made. If rename is successful, we've successfully stole partially downloaded file and can resume download. If rename isn't successful, we download the whole file. If we fail in the middle of download (broken network, CTRL+C, etc), weos.Rename("<random>", "<sha>.tmp")so we can resume download next time. In case of hard fail (SIGKILL, poweroff) we won't be able to resume download, though this doesn't look like a big problem. To be honest, I haven't heard of any software that works this way.2.4. Introduce a huge lock file (like
.git/index.lock) that will guard all write operations to LFS storage. Ideally, this lock should be even more complex because in git-lfs there are three types of operations - read, fetch and prune. However, like with.git/index.lock, such thing will cause pains because it will from time to time get stuck.I also want to note that this issue is not specific to shared
lfs.storageacross several working copies. It is also possible to trigger multiplegit-lfsprocesses working on the same file even with a single working copy, for example by running severalgit show <commit-ish>:<path/to/lfs/file>at the same timebk2204 commentedon Sep 18, 2019
Removal of download resuming is not an option. Folks in many parts of the world have unreliable connections, and even people who usually have good connections sometimes get on airplanes where the WiFi is bad.
We definitely need some sort of locking here. Unfortunately, flock is not a viable choice because it doesn't work on NFS, and I'm sure we have folks using NFS. That means that we need to use fcntl locking or dotlocking (using the algorithm specified in Linux's
open(2)manpage underO_EXCL) and, if we're using fcntl locking, avoid opening multiple file descriptors to the same file. I have no clue which if any of these will work on Windows, though.Adopting the same algorithm Git uses when writing refs for use when we're writing objects sounds like a reasonable plan; we know it's generally reliable and we know it works on NFS. Since we may not want to rewrite the object to the side and rename over it, it sounds like this is describing option 2.3, which could be reasonable.
More robust handling of parallel attempts to download the same file
More robust handling of parallel attempts to download the same file
More robust handling of parallel attempts to download the same file
More robust handling of parallel attempts to download the same file
Stop replacing files in LFS storage when downloading them concurrently
Stop replacing files in LFS storage when downloading them concurrently
Stop replacing files in LFS storage when downloading them concurrently
Stop replacing files in LFS storage when downloading them concurrently
Stop replacing files in LFS storage when downloading them concurrentl…
Stop replacing files in LFS storage when downloading them concurrentl…
Stop replacing files in LFS storage when downloading them concurrentl…
slonopotamus commentedon Oct 25, 2019
#3880 got just merged. Hopefully, this ends the story of issues with parallel usage of LFS storage.
UPD: no, it didn't. But #3890 did.
docs: reference related issues in shared cache proposal