diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2022-03-15 19:12:46 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2022-03-19 21:33:51 +0100 |
commit | 7b1c8cf147b5ecd8f77bf6d3d64c40acd643af83 (patch) | |
tree | 24a60e396cfcd507d1c0e1ae3daceb777f04c1fd /org.eclipse.jgit.lfs.test | |
parent | ac78c175231979c7c5ab361980a233edee7626df (diff) | |
download | jgit-7b1c8cf147b5ecd8f77bf6d3d64c40acd643af83.tar.gz jgit-7b1c8cf147b5ecd8f77bf6d3d64c40acd643af83.zip |
Re-try reading a file when there are concurrent writes
Git and JGit are very careful to replace git files atomically when
writing. The normal mechanism for this is to write to a temporary
file and then to rename it atomically to the final destination. This
works fine on POSIX-compliant systems, but on systems where renaming
may not be atomic, exceptions may be thrown if code tries to read
the file while the rename is still ongoing. This happens in particular
on Windows, where the typical symptom is that a FileNotFoundException
with message "The process cannot access the file because it is being
used by another process" is thrown, but file.isFile() == true at the
same time.
In FileBasedConfig, a re-try was already implemented for this case.
But the same problem can also occur in other places, for instance
in RefDirectory when reading loose or packed refs. Additionally,
JGit has similar re-tries when a stale NFS file handle is detected,
but that mechanism wasn't used consistently (only for git configs
and packed refs, but not for loose refs).
Factor out the general re-try mechanism for reading into a new method
FileUtils.readWithRetry() and use that in all three places. The
re-try parameters are hardcoded: at most 5 times for stale NFS handles,
and at most 5 times with increasing backoff delays (50, 100, 200, 400,
and 800ms) for the above concurrent write case.
Bug: 579116
Change-Id: If0c2ad367446d3c0f32b509274cf8e814aca12cf
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.lfs.test')
0 files changed, 0 insertions, 0 deletions