assistant: Fix deadlock that could occur when adding a lot of files at once in indirect mode.

This is a laziness problem. Despite the bang pattern on newfiles, the list
was not being fully evaluated before cleanup was called. Moving cleanup out
to after the list is actually used fixes this.

More evidence that I should be using ResourceT or pipes, if any was needed.
This commit is contained in:
Joey Hess 2013-07-26 18:42:22 -04:00
parent de066200f3
commit ec4d974dcf
2 changed files with 9 additions and 7 deletions

View file

@ -5,7 +5,7 @@
- Licensed under the GNU GPL version 3 or higher. - Licensed under the GNU GPL version 3 or higher.
-} -}
{-# LANGUAGE CPP, BangPatterns #-} {-# LANGUAGE CPP #-}
module Assistant.Threads.Committer where module Assistant.Threads.Committer where
@ -273,10 +273,11 @@ handleAdds :: Maybe Seconds -> [Change] -> Assistant [Change]
handleAdds delayadd cs = returnWhen (null incomplete) $ do handleAdds delayadd cs = returnWhen (null incomplete) $ do
let (pending, inprocess) = partition isPendingAddChange incomplete let (pending, inprocess) = partition isPendingAddChange incomplete
direct <- liftAnnex isDirect direct <- liftAnnex isDirect
pending' <- if direct (pending', cleanup) <- if direct
then return pending then return (pending, noop)
else findnew pending else findnew pending
(postponed, toadd) <- partitionEithers <$> safeToAdd delayadd pending' inprocess (postponed, toadd) <- partitionEithers <$> safeToAdd delayadd pending' inprocess
cleanup
unless (null postponed) $ unless (null postponed) $
refillChanges postponed refillChanges postponed
@ -294,14 +295,13 @@ handleAdds delayadd cs = returnWhen (null incomplete) $ do
where where
(incomplete, otherchanges) = partition (\c -> isPendingAddChange c || isInProcessAddChange c) cs (incomplete, otherchanges) = partition (\c -> isPendingAddChange c || isInProcessAddChange c) cs
findnew [] = return [] findnew [] = return ([], noop)
findnew pending@(exemplar:_) = do findnew pending@(exemplar:_) = do
(!newfiles, cleanup) <- liftAnnex $ (newfiles, cleanup) <- liftAnnex $
inRepo (Git.LsFiles.notInRepo False $ map changeFile pending) inRepo (Git.LsFiles.notInRepo False $ map changeFile pending)
void $ liftIO cleanup
-- note: timestamp info is lost here -- note: timestamp info is lost here
let ts = changeTime exemplar let ts = changeTime exemplar
return $ map (PendingAddChange ts) newfiles return (map (PendingAddChange ts) newfiles, void $ liftIO $ cleanup)
returnWhen c a returnWhen c a
| c = return otherchanges | c = return otherchanges

2
debian/changelog vendored
View file

@ -17,6 +17,8 @@ git-annex (4.20130724) UNRELEASED; urgency=low
transferred. transferred.
* assistant: Fix NetWatcher to not sync with remotes that have * assistant: Fix NetWatcher to not sync with remotes that have
remote.<name>.annex-sync set to false. remote.<name>.annex-sync set to false.
* assistant: Fix deadlock that could occur when adding a lot of files
at once in indirect mode.
-- Joey Hess <joeyh@debian.org> Tue, 23 Jul 2013 12:39:48 -0400 -- Joey Hess <joeyh@debian.org> Tue, 23 Jul 2013 12:39:48 -0400