Re: [JGIT PATCH v2] Fix a race condition when loading non-mmapd byte windows
"Shawn O. Pearce" <spearce@spearce.org> wrote:
> Oh hell, I missed the fact that markLoaded(ByteWindow) may be
> dropping the last reference and need to close the file.
*and* you need to squash this in to prevent a deadlock:
Frell. What a Saturday.
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ByteArrayWindow.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ByteArrayWindow.java
index 055a329..c07a260 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ByteArrayWindow.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ByteArrayWindow.java
@@ -100,16 +100,25 @@ void inflateVerify(final byte[] array, final int pos, final Inflater inf)
inf.inflate(verifyGarbageBuffer, 0, verifyGarbageBuffer.length);
}
- synchronized void ensureLoaded(final byte[] array) {
- if (!loaded) {
- try {
- provider.fd.getChannel().read(ByteBuffer.wrap(array), start);
- } catch (IOException e) {
- throw new RuntimeException("Cannot fault in window", e);
- } finally {
+ void ensureLoaded(final byte[] array) {
+ boolean release = false;
+ try {
+ synchronized (this) {
+ if (!loaded) {
+ release = true;
+ try {
+ provider.fd.getChannel().read(ByteBuffer.wrap(array),
+ start);
+ } catch (IOException e) {
+ throw new RuntimeException("Cannot fault in window", e);
+ }
+ loaded = true;
+ }
+ }
+ } finally {
+ if (release) {
WindowCache.markLoaded(this);
}
- loaded = true;
}
}
}
\ No newline at end of file
--
Shawn.