Better ssh connection warmup when using -J for concurrency.
Avoids ugly messages when forced ssh command is not git-annex-shell. This commit was sponsored by Ole-Morten Duesund on Patreon.
This commit is contained in:
parent
460ab8a181
commit
3dd43df9c2
5 changed files with 60 additions and 40 deletions
57
Annex/Ssh.hs
57
Annex/Ssh.hs
|
@ -202,36 +202,33 @@ prepSocket socketfile gc sshhost sshparams = do
|
||||||
-- the connection has already been started. Otherwise,
|
-- the connection has already been started. Otherwise,
|
||||||
-- get the connection started now.
|
-- get the connection started now.
|
||||||
makeconnection socketlock =
|
makeconnection socketlock =
|
||||||
whenM (isNothing <$> fromLockCache socketlock) $ do
|
whenM (isNothing <$> fromLockCache socketlock) $
|
||||||
let startps = Param (fromSshHost sshhost) :
|
-- See if ssh can connect in batch mode,
|
||||||
sshparams ++ startSshConnection gc
|
-- if so there's no need to block for a password
|
||||||
-- When we can start the connection in batch mode,
|
-- prompt.
|
||||||
-- ssh won't prompt to the console.
|
unlessM (tryssh ["-o", "BatchMode=true"]) $
|
||||||
(_, connected) <- liftIO $ processTranscript "ssh"
|
-- ssh needs to prompt (probably)
|
||||||
(["-o", "BatchMode=true"]
|
-- If the user enters the wrong password,
|
||||||
++ toCommand startps)
|
-- ssh will tell them, so we can ignore
|
||||||
Nothing
|
-- failure.
|
||||||
unless connected $ do
|
void $ prompt $ tryssh []
|
||||||
ok <- prompt $ liftIO $
|
-- Try to ssh to the host quietly. Returns True if ssh apparently
|
||||||
boolSystem "ssh" startps
|
-- connected to the host successfully. If ssh failed to connect,
|
||||||
unless ok $
|
-- returns False.
|
||||||
warning $ "Unable to run git-annex-shell on remote " ++
|
-- Even if ssh is forced to run some specific command, this will
|
||||||
Git.repoDescribe (gitConfigRepo (remoteGitConfig gc))
|
-- return True.
|
||||||
|
-- (Except there's an unlikely false positive where a forced
|
||||||
-- Parameters to get ssh connected to the remote host,
|
-- ssh command exits 255.)
|
||||||
-- by asking it to run a no-op command.
|
tryssh extraps = liftIO $ do
|
||||||
--
|
let p = proc "ssh" $ concat
|
||||||
-- Could simply run "true", but the remote host may only
|
[ extraps
|
||||||
-- allow git-annex-shell to run. So, run git-annex-shell inannex
|
, toCommand sshparams
|
||||||
-- with the path to the remote repository and no other parameters,
|
, [fromSshHost sshhost, "true"]
|
||||||
-- which is a no-op supported by all versions of git-annex-shell.
|
]
|
||||||
startSshConnection :: RemoteGitConfig -> [CommandParam]
|
(_, exitcode) <- processTranscript'' p Nothing
|
||||||
startSshConnection gc =
|
return $ case exitcode of
|
||||||
[ Param "git-annex-shell"
|
ExitFailure 255 -> False
|
||||||
, Param "inannex"
|
_ -> True
|
||||||
, File $ Git.repoPath $ gitConfigRepo $
|
|
||||||
remoteGitConfig gc
|
|
||||||
]
|
|
||||||
|
|
||||||
{- Find ssh socket files.
|
{- Find ssh socket files.
|
||||||
-
|
-
|
||||||
|
|
|
@ -17,6 +17,8 @@ git-annex (6.20180228) UNRELEASED; urgency=medium
|
||||||
present when locking it. This could cause git annex drop to remove
|
present when locking it. This could cause git annex drop to remove
|
||||||
the only copy of a file when it thought the tor remote had a copy.
|
the only copy of a file when it thought the tor remote had a copy.
|
||||||
* git-annex-shell: Added p2pstdio mode.
|
* git-annex-shell: Added p2pstdio mode.
|
||||||
|
* Better ssh connection warmup when using -J for concurrency.
|
||||||
|
Avoids ugly messages when forced ssh command is not git-annex-shell.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Wed, 28 Feb 2018 11:53:03 -0400
|
-- Joey Hess <id@joeyh.name> Wed, 28 Feb 2018 11:53:03 -0400
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{- Process transcript
|
{- Process transcript
|
||||||
-
|
-
|
||||||
- Copyright 2012-2015 Joey Hess <id@joeyh.name>
|
- Copyright 2012-2018 Joey Hess <id@joeyh.name>
|
||||||
-
|
-
|
||||||
- License: BSD-2-clause
|
- License: BSD-2-clause
|
||||||
-}
|
-}
|
||||||
|
@ -13,6 +13,7 @@ module Utility.Process.Transcript where
|
||||||
import Utility.Process
|
import Utility.Process
|
||||||
|
|
||||||
import System.IO
|
import System.IO
|
||||||
|
import System.Exit
|
||||||
import Control.Concurrent
|
import Control.Concurrent
|
||||||
import qualified Control.Exception as E
|
import qualified Control.Exception as E
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
@ -24,14 +25,19 @@ import Control.Applicative
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
-- | Runs a process, optionally feeding it some input, and
|
-- | Runs a process and returns a transcript combining its stdout and
|
||||||
-- returns a transcript combining its stdout and stderr, and
|
-- stderr, and whether it succeeded or failed.
|
||||||
-- whether it succeeded or failed.
|
|
||||||
processTranscript :: String -> [String] -> (Maybe String) -> IO (String, Bool)
|
processTranscript :: String -> [String] -> (Maybe String) -> IO (String, Bool)
|
||||||
processTranscript cmd opts = processTranscript' (proc cmd opts)
|
processTranscript cmd opts = processTranscript' (proc cmd opts)
|
||||||
|
|
||||||
|
-- | Also feeds the process some input.
|
||||||
processTranscript' :: CreateProcess -> Maybe String -> IO (String, Bool)
|
processTranscript' :: CreateProcess -> Maybe String -> IO (String, Bool)
|
||||||
processTranscript' cp input = do
|
processTranscript' cp input = do
|
||||||
|
(t, c) <- processTranscript'' cp input
|
||||||
|
return (t, c == ExitSuccess)
|
||||||
|
|
||||||
|
processTranscript'' :: CreateProcess -> Maybe String -> IO (String, ExitCode)
|
||||||
|
processTranscript'' cp input = do
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
{- This implementation interleves stdout and stderr in exactly the order
|
{- This implementation interleves stdout and stderr in exactly the order
|
||||||
- the process writes them. -}
|
- the process writes them. -}
|
||||||
|
@ -48,9 +54,6 @@ processTranscript' cp input = do
|
||||||
get <- mkreader readh
|
get <- mkreader readh
|
||||||
writeinput input p
|
writeinput input p
|
||||||
transcript <- get
|
transcript <- get
|
||||||
|
|
||||||
ok <- checkSuccessProcess pid
|
|
||||||
return (transcript, ok)
|
|
||||||
#else
|
#else
|
||||||
{- This implementation for Windows puts stderr after stdout. -}
|
{- This implementation for Windows puts stderr after stdout. -}
|
||||||
p@(_, _, _, pid) <- createProcess $ cp
|
p@(_, _, _, pid) <- createProcess $ cp
|
||||||
|
@ -63,10 +66,9 @@ processTranscript' cp input = do
|
||||||
geterr <- mkreader (stderrHandle p)
|
geterr <- mkreader (stderrHandle p)
|
||||||
writeinput input p
|
writeinput input p
|
||||||
transcript <- (++) <$> getout <*> geterr
|
transcript <- (++) <$> getout <*> geterr
|
||||||
|
|
||||||
ok <- checkSuccessProcess pid
|
|
||||||
return (transcript, ok)
|
|
||||||
#endif
|
#endif
|
||||||
|
code <- waitForProcess pid
|
||||||
|
return (transcript, code)
|
||||||
where
|
where
|
||||||
mkreader h = do
|
mkreader h = do
|
||||||
s <- hGetContents h
|
s <- hGetContents h
|
||||||
|
|
|
@ -30,3 +30,4 @@ git-annex version: 6.20180227-g32d682dd8 (standalone version) on Debian stretch
|
||||||
As always, I'm a fan :>
|
As always, I'm a fan :>
|
||||||
|
|
||||||
|
|
||||||
|
> [[fixed|done]] --[[Joey]]
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
[[!comment format=mdwn
|
||||||
|
username="joey"
|
||||||
|
subject="""comment 4"""
|
||||||
|
date="2018-03-07T20:25:10Z"
|
||||||
|
content="""
|
||||||
|
Ok, this involves the fairly recently added support for
|
||||||
|
avoding overlapping ssh password prompts when running multiple ssh
|
||||||
|
processes concurrently.
|
||||||
|
|
||||||
|
In -J mode, git-annex warms up the ssh connection by running
|
||||||
|
"git-annex-shell inannex". Your rrsync config prevents that being run.
|
||||||
|
|
||||||
|
This doesn't actually cause a problem, the connection is still warmed up.
|
||||||
|
If you needed a password to connect, it would have prompted for it before
|
||||||
|
the error message from rrsync.
|
||||||
|
|
||||||
|
But it's ugly.. I've committed a fix that will avoid the ugly messages.
|
||||||
|
"""]]
|
Loading…
Add table
Add a link
Reference in a new issue