assistant: Avoid startup hang on active *.lock file
authorJoey Hess <joeyh@joeyh.name>
Thu, 22 May 2025 16:56:31 +0000 (12:56 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 22 May 2025 16:56:58 +0000 (12:56 -0400)
Avoid hanging at startup when a process has a *.lock file open in the .git
directory.

The goal is to repair stale locks, not wait for all active locks to be
closed. This was causing problems for a non-git process that has its own
lock file in a subdir of .git/.

If .git/index_lock is a non-stale lock, this does let the assistant start
up regardless. Commits by the assistant will then fail, until the process
locking the index finishes. This is not a problem, because the same
behavior could already happen if the assistant is started and then another
process locks the index.

Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project
Assistant/Repair.hs
CHANGELOG
doc/bugs/assistant_does_not_commit_anything__44___waiting__63__.mdwn
doc/bugs/assistant_does_not_commit_anything__44___waiting__63__/comment_4_73717884bf2129c55a894e7f1fff490c._comment [new file with mode: 0644]

index c024f93e6f740c1f7704a32395a587f2aa62e3e9..1dd549d694e80e9997631dac4ef1a3e902f0af5e 100644 (file)
@@ -147,17 +147,10 @@ repairStaleLocks lockfiles = go =<< getsizes
                <$> getFileSize lf
        getsizes = liftIO $ catMaybes <$> mapM getsize lockfiles
        go [] = return ()
-       go l = ifM (liftIO $ null <$> Lsof.query ("--" : map (fromOsPath . fst) l))
-               ( do
-                       waitforit "to check stale git lock file"
-                       l' <- getsizes
-                       if l' == l
-                               then liftIO $ mapM_ (removeWhenExistsWith removeFile . fst) l
-                               else go l'
-               , do
-                       waitforit "for git lock file writer"
-                       go =<< getsizes
-               )
-       waitforit why = do
-               debug ["Waiting for 60 seconds", why]
+       go l = whenM (liftIO $ null <$> Lsof.query ("--" : map (fromOsPath . fst) l)) $ do
+               debug ["Waiting for 60 seconds to check stale git lock file"]
                liftIO $ threadDelaySeconds $ Seconds 60
+               l' <- getsizes
+               if l' == l
+                       then liftIO $ mapM_ (removeWhenExistsWith removeFile . fst) l
+                       else go l'
index 3cdecf1b1da610a3f4dd87d6edb5e6e2466f8a53..8f5771b5f71d0544de63ca4bd238bbfceef3e462 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,10 @@
+git-annex (10.20250521) UNRELEASED; urgency=medium
+
+  * assistant: Avoid hanging at startup when a process has a *.lock file
+    open in the .git directory.
+
+ -- Joey Hess <id@joeyh.name>  Thu, 22 May 2025 12:43:38 -0400
+
 git-annex (10.20250520) upstream; urgency=medium
 
   * Preferred content now supports "balanced=groupname:lackingcopies"
index dbf3f812275a6863e9fa0ae96db10d19d1c7d59e..aed7f2c8c120bcc1c598dcf7d7e2b7a0d09e2ab9 100644 (file)
@@ -87,3 +87,5 @@ Please advise
 
 [[!meta author=yoh]]
 [[!tag projects/repronim]]
+
+> [[fixed|done]] --[[Joey]]
diff --git a/doc/bugs/assistant_does_not_commit_anything__44___waiting__63__/comment_4_73717884bf2129c55a894e7f1fff490c._comment b/doc/bugs/assistant_does_not_commit_anything__44___waiting__63__/comment_4_73717884bf2129c55a894e7f1fff490c._comment
new file mode 100644 (file)
index 0000000..a231d0d
--- /dev/null
@@ -0,0 +1,17 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 4"""
+ date="2025-05-22T16:19:35Z"
+ content="""
+It's treating `*.lock` as git lock files. Any other filename won't have the
+problem.
+
+[[!commit 635c9a1549f28992b6ae370f6e8687170c971525]] has a rationalle for
+that, that git has other lock files than index.lock. It does seem to me to
+be doubtful that any other stale git lock than index.lock would cause
+significant trouble to the assistant.
+
+But this code is supposed to deal with stale locks. This lock is not
+stale; it has a process holding it open. So the assistant has no
+reason to wait on it. I've removed the wait loop.
+"""]]