Re: [JGIT PATCH v2] Fix a race condition when loading non-mmapd byte windows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Shawn O. Pearce" <spearce@xxxxxxxxxxx> 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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux