summaryrefslogtreecommitdiff
path: root/Remote/Git.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-08-03 20:14:20 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-08-03 20:14:20 -0400
commit1f55c2a00d47290af6198e2df06a9d2e406fcff1 (patch)
tree56a819c0837e46308dff56342e4c17ea57065c3f /Remote/Git.hs
parentde856bc585ee19800a98a062e47daad01a8d94e1 (diff)
finally properly fixed ssh zombie leak
The leak was caused by the thread that sshd'd to send transferinfo not waiting on its ssh. Doh.
Diffstat (limited to 'Remote/Git.hs')
-rw-r--r--Remote/Git.hs9
1 files changed, 8 insertions, 1 deletions
diff --git a/Remote/Git.hs b/Remote/Git.hs
index 4498ec907..bf2228c49 100644
--- a/Remote/Git.hs
+++ b/Remote/Git.hs
@@ -390,6 +390,7 @@ copyFromRemote' r key file dest
Just (cmd, params) <- Ssh.git_annex_shell (repo r) "transferinfo"
[Param $ key2file key] fields
v <- liftIO (newEmptySV :: IO (MSampleVar Integer))
+ pidv <- liftIO $ newEmptyMVar
tid <- liftIO $ forkIO $ void $ tryIO $ do
bytes <- readSV v
p <- createProcess $
@@ -397,6 +398,7 @@ copyFromRemote' r key file dest
{ std_in = CreatePipe
, std_err = CreatePipe
}
+ putMVar pidv (processHandle p)
hClose $ stderrHandle p
let h = stdinHandle p
let send b = do
@@ -406,7 +408,12 @@ copyFromRemote' r key file dest
forever $
send =<< readSV v
let feeder = writeSV v . fromBytesProcessed
- bracketIO noop (const $ tryIO $ killThread tid) (const $ a feeder)
+ let cleanup = do
+ void $ tryIO $ killThread tid
+ tryNonAsync $
+ maybe noop (void . waitForProcess)
+ =<< tryTakeMVar pidv
+ bracketIO noop (const cleanup) (const $ a feeder)
copyFromRemoteCheap :: Remote -> Key -> FilePath -> Annex Bool
#ifndef mingw32_HOST_OS