From 7476183589f4c255ea561be9dff0109fc8919e9f Mon Sep 17 00:00:00 2001 From: Dariusz Luksza Date: Mon, 20 Nov 2023 11:53:19 +0000 Subject: [PATCH] Improve handling of NFS stale handle errors Mark packfile as invalid when NFS stale handle error occurs. This should fix broken fetch operations when the repo is located on the NFS system and is GC'ed on a separate system (or process). Which may result in the index, pack or bitmap file being removed when they are accessed from the fetch operation. Bug: 573770 Signed-off-by: Dariusz Luksza Change-Id: I70217bfb93bf7421ea2c1d74cbe4f15c76d9c098 (cherry picked from commit c701c01b49d92993f1c3df0a0e26a2dd68b8cec1) --- .../eclipse/jgit/internal/storage/file/Pack.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java index 29f936587d..d6c25b2587 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java @@ -56,6 +56,7 @@ import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectLoader; +import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.LongList; import org.eclipse.jgit.util.NB; import org.eclipse.jgit.util.RawParseUtils; @@ -665,7 +666,12 @@ public class Pack implements Iterable { // exceptions signaling permanent problems with a pack openFail(true, pe); throw pe; - } catch (IOException | RuntimeException ge) { + } catch (IOException ioe) { + // mark this packfile as invalid when NFS stale file handle error + // occur + openFail(FileUtils.isStaleFileHandleInCausalChain(ioe), ioe); + throw ioe; + } catch (RuntimeException ge) { // generic exceptions could be transient so we should not mark the // pack invalid to avoid false MissingObjectExceptions openFail(false, ge); @@ -1134,6 +1140,14 @@ public class Pack implements Iterable { // removed index, packfile or the bitmap bitmapIdxFile = null; return null; + } catch (IOException e) { + if (!FileUtils.isStaleFileHandleInCausalChain(e)) { + throw e; + } + // Ignore NFS stale handle exception the same way as + // FileNotFoundException above. + bitmapIdxFile = null; + return null; } // At this point, idx() will have set packChecksum. -- 2.39.5