Fix a hang when using git-annex with an old openssh 7.2p2

Which had some weird inheriting of ssh FDs by sshd.

Bug was introduced in git-annex version 7.20200202.7.
This commit is contained in:
Joey Hess 2020-07-21 16:14:25 -04:00
parent b75aa68bfa
commit cb74cefde7
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 61 additions and 7 deletions

View file

@ -22,6 +22,7 @@ import Git.Types
import qualified Git.Command
import qualified Git.Construct
import Utility.UserInfo
import Utility.ThreadScheduler
{- Returns a single git config setting, or a fallback value if not set. -}
get :: ConfigKey -> ConfigValue -> Repo -> ConfigValue
@ -214,13 +215,20 @@ fromPipe r cmd params st = tryNonAsync $ withCreateProcess p go
{ std_out = CreatePipe
, std_err = CreatePipe
}
go _ (Just hout) (Just herr) pid = do
(val, err) <- concurrently
(S.hGetContents hout)
(S.hGetContents herr)
forceSuccessProcess p pid
r' <- store val st r
return (r', val, err)
go _ (Just hout) (Just herr) pid =
withAsync (S.hGetContents herr) $ \errreader -> do
val <- S.hGetContents hout
-- In case the process exits while something else,
-- like a background process, keeps the stderr handle
-- open, don't block forever waiting for stderr.
-- A few seconds after finishing reading stdout
-- should get any error message.
err <- either id id <$>
wait errreader
`race` (threadDelaySeconds (Seconds 2) >> return mempty)
forceSuccessProcess p pid
r' <- store val st r
return (r', val, err)
go _ _ _ _ = error "internal"
{- Reads git config from a specified file and returns the repo populated