git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Shawn O. Pearce <spearce@spearce.org>
Date
Mar 8, 2009, 01:24 UTC
Message-ID
<20090308012415.GT16213@spearce.org>
In-Reply-To
<1236471435-21888-1-git-send-email-spearce@spearce.org>
"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.
Previous: Shawn O. Pearce
Message 3 of 3 in “Fix a race condition when loading non-mmapd byte windows”
  1. Fix a race condition when loading non-mmapd byte windowsShawn O. Pearce, Mar 8, 2009
  2. Fix a race condition when loading non-mmapd byte windowsShawn O. Pearce, Mar 8, 2009
  3. Shawn O. PearceMar 8, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.