Run ssh with ServerAliveInterval 60

So that stalled transfers will be noticed within about 3 minutes,
even if TCPKeepAlive is disabled or doesn't work.

Rather than setting with -o, use -F with another config file,
so that any settings in ~/.ssh/config or /etc/ssh/ssh_config overrides this.
This commit is contained in:
Joey Hess 2016-10-26 16:41:34 -04:00
parent 075602b1df
commit 0ae08947ac
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
5 changed files with 45 additions and 11 deletions

View file

@ -63,6 +63,7 @@ module Annex.Locations (
gitAnnexUrlFile,
gitAnnexTmpCfgFile,
gitAnnexSshDir,
gitAnnexSshConfig,
gitAnnexRemotesDir,
gitAnnexAssistantDefaultDir,
HashLevels(..),
@ -402,6 +403,10 @@ gitAnnexTmpCfgFile r = gitAnnexDir r </> "config.tmp"
gitAnnexSshDir :: Git.Repo -> FilePath
gitAnnexSshDir r = addTrailingPathSeparator $ gitAnnexDir r </> "ssh"
{- .git/annex/ssh.config is used to configure ssh. -}
gitAnnexSshConfig :: Git.Repo -> FilePath
gitAnnexSshConfig r = gitAnnexDir r </> "ssh.config"
{- .git/annex/remotes/ is used for remote-specific state. -}
gitAnnexRemotesDir :: Git.Repo -> FilePath
gitAnnexRemotesDir r = addTrailingPathSeparator $ gitAnnexDir r </> "remotes"

View file

@ -33,6 +33,7 @@ import qualified Git.Url
import Config
import Annex.Path
import Utility.Env
import Utility.Tmp
import Types.CleanupActions
import Git.Env
#ifndef mingw32_HOST_OS
@ -49,13 +50,33 @@ sshOptions (host, port) gc opts = go =<< sshCachingInfo (host, port)
go (Just socketfile, params) = do
prepSocket socketfile
ret params
ret ps = return $ concat
[ ps
, map Param (remoteAnnexSshOptions gc)
, opts
, portParams port
, [Param "-T"]
]
ret ps = do
overideconfigfile <- fromRepo gitAnnexSshConfig
-- We assume that the file content does not change.
-- If it did, a more expensive test would be needed.
liftIO $ unlessM (doesFileExist overideconfigfile) $
viaTmp writeFile overideconfigfile $ unlines
-- ssh expands "~"
[ "Include ~/.ssh/config"
-- ssh will silently skip the file
-- if it does not exist
, "Include /etc/ssh/ssh_config"
-- Everything below this point is only
-- used if there's no setting for it in
-- the above files.
--
-- Make sure that ssh detects stalled
-- connections.
, "ServerAliveInterval 60"
]
return $ concat
[ ps
, [Param "-F", File overideconfigfile]
, map Param (remoteAnnexSshOptions gc)
, opts
, portParams port
, [Param "-T"]
]
{- Returns a filename to use for a ssh connection caching socket, and
- parameters to enable ssh connection caching. -}

View file

@ -14,6 +14,10 @@ git-annex (6.20161013) UNRELEASED; urgency=medium
NFS sometimes puts in a directory when a file is being deleted.
* If a transfer fails for some reason, but some data managed to be sent,
the transfer will be retried. (The assistant already did this.)
* Run ssh with ServerAliveInterval 60, so that stalled transfers will
be noticed within about 3 minutes.
(Any setting in your ~/.ssh/config or /etc/ssh/ssh_config
overrides this.)
-- Joey Hess <id@joeyh.name> Mon, 17 Oct 2016 12:46:54 -0400

View file

@ -59,3 +59,5 @@ SHA256E-s41311329--69c3b054a3fe9676133605730d85b7fcef8696f6782d402a524e41b836253
[[!meta title="Detect stalled transfer and retry or abort it"]]
> [[done]] --[[Joey]]

View file

@ -6,12 +6,12 @@
On the ssh config, one way to do it is to pass -F with a config
file that git-annex generates. It could look like:
Include ~/.ssh/ssh.config
Include /etc/ssh/ssh.config
Include ~/.ssh/config
Include /etc/ssh/ssh_config
ServerAliveInterval 60
Since ssh uses the first config setting it sees, if ~/.ssh/ssh.config
or /etc/ssh/ssh.config set a ServerAliveInterval that one will be used,
Since ssh uses the first config setting it sees, if `~/.ssh/config`
or `/etc/ssh/ssh_config` set a ServerAliveInterval that one will be used,
and otherwise the value git-annex sets will be used.
But.. Ssh enables TCPKeepAlive by default. You'd think that would be enough
@ -23,4 +23,6 @@ or a firewall does not support it.
If the problem is that users are disabling TCPKeepAlive, then
having git-annex enable ServerAliveInterval makes sense.
Ok; implemented this.
"""]]