fix process and FD leak

Fix process and file descriptor leak that was exposed when git-annex was
built with ghc 8.2.1. Apparently ghc has changed its behavior of GC
of open file handles that are pipes to running processes. That
broke git-annex test on OSX due to running out of FDs.

Audited for all uses of Annex.new and made stopCoProcesses be called
once it's done with the state. Fixed several places that might have
leaked in other situations than running the test suite.

This commit was sponsored by Ewen McNeill.
This commit is contained in:
Joey Hess 2017-09-29 22:36:08 -04:00
parent b14ad56275
commit 5c32196a37
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
7 changed files with 32 additions and 21 deletions

View file

@ -59,7 +59,7 @@ import Annex.Path
import Creds
import Messages.Progress
import Types.NumCopies
import Annex.Concurrent
import Annex.Action
import Control.Concurrent
import Control.Concurrent.MSampleVar
@ -311,11 +311,12 @@ tryGitConfigRead autoinit r
- it if allowed. However, if that fails, still return the read
- git config. -}
readlocalannexconfig = do
s <- Annex.new r
Annex.eval s $ do
let check = do
Annex.BranchState.disableUpdate
void $ tryNonAsync $ ensureInitialized
Annex.getState Annex.repo
s <- Annex.new r
Annex.eval s $ check `finally` stopCoProcesses
configlistfields = if autoinit
then [(Fields.autoInit, "1")]
@ -611,7 +612,7 @@ repairRemote r a = return $ do
Annex.eval s $ do
Annex.BranchState.disableUpdate
ensureInitialized
a
a `finally` stopCoProcesses
{- Runs an action from the perspective of a local remote.
-
@ -632,7 +633,7 @@ onLocal r a = do
go st = do
curro <- Annex.getState Annex.output
(ret, st') <- liftIO $ Annex.run (st { Annex.output = curro }) $
stopCoProcesses `after` a
a `finally` stopCoProcesses
cache st'
return ret