]> source.dussan.org Git - jgit.git/commit
FileBasedConfig: in-process synchronization for load() and save() 23/204923/1
authorThomas Wolf <twolf@apache.org>
Sat, 14 Oct 2023 21:25:19 +0000 (23:25 +0200)
committerThomas Wolf <twolf@apache.org>
Sat, 14 Oct 2023 21:33:11 +0000 (23:33 +0200)
commit0f078da4e45c90e1800fd16ee75c2934b4d58932
tree2b65220d1223e73949c6167035441ce6bc92e600
parentf6774fa8ee09f51ace5257b6cc43b7886b3f285a
FileBasedConfig: in-process synchronization for load() and save()

On Windows reading and replacing a file via renaming concurrently may
fail either in the reader or in the thread renaming the file. For
renaming, FileUtils.rename() has a last-case fallback in which it
deletes the target file before attempting the rename. If a reader reads
at that moment, it will produce an empty config, and the snapshot and
hash may be wrong because the concurrently running save() may set them.

It's not really possible to do all this in a thread-safe manner without
some synchronization. Add a read-write lock to synchronize readers and
writers to avoid at least that JGit steps on its own feet.

Bug: 451508
Change-Id: I7e5f0f26e02f34ba02dc925a445044d3e21389b4
Signed-off-by: Thomas Wolf <twolf@apache.org>
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java