]> source.dussan.org Git - jgit.git/commit
SnapshottingRefDirectory: Invalidate snapshot after locking ref for 75/1176275/4
authorNasser Grainawi <quic_nasserg@quicinc.com>
Thu, 25 Jan 2024 23:29:05 +0000 (16:29 -0700)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 13 Feb 2024 14:48:31 +0000 (15:48 +0100)
commit29c89d1f02e84d0395e12f55204bd129e61c43bf
tree4c28f4ed879490ee574541d0a83001c3763060e9
parent8197cab33758677eacd2cf253e912f0d23068934
SnapshottingRefDirectory: Invalidate snapshot after locking ref for
update

When using the SnapshottingRefDirectory, if a thread has already read
packed-refs, then another actor updates packed-refs, the original
thread may create an update that is based on the old cached/snapshotted
packed-refs content. That update could effectively perform a forced
update unintentionally because it is unaware of the new content.

This seems particularly likely to happen in a scenario where a loose
ref was just packed. If the ref was loose, our thread would see the
current ref value (because we don't snapshot loose refs and always read
them from disk), but since there is no loose ref, we expect to find the
current value in packed-refs. However, (before this change) we rely
on our snapshot of packed-refs which does not contain the updated ref
value.

Invalidating the cache after the loose ref is locked ensures that the
ref value does not change again before we read it to perform the update.

Bug: jgit-21
Change-Id: Id10900a99bfd0401a1b9c39d997093af0289649e
Signed-off-by: Nasser Grainawi <quic_nasserg@quicinc.com>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryUpdate.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/SnapshottingRefDirectory.java