1
0
mirror of https://github.com/zrepl/zrepl.git synced 2025-04-25 20:09:40 +02:00

ssh+stdinserver: connect: dial_timeout

This  is a follow-up to ccd062e
This commit is contained in:
Christian Schwarz 2018-03-04 17:19:41 +01:00
parent 61af396fdd
commit 26b436463d
4 changed files with 30 additions and 5 deletions

2
Gopkg.lock generated
View File

@ -83,7 +83,7 @@
branch = "master" branch = "master"
name = "github.com/problame/go-netssh" name = "github.com/problame/go-netssh"
packages = ["."] packages = ["."]
revision = "ffa145d2506e222977205e7666a9722d6b9959ac" revision = "984ce91f575c75c4d5d6c7e74660d2c837571496"
[[projects]] [[projects]]
branch = "master" branch = "master"

View File

@ -9,6 +9,7 @@ import (
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/problame/go-netssh" "github.com/problame/go-netssh"
"time"
) )
type SSHStdinserverConnecter struct { type SSHStdinserverConnecter struct {
@ -19,6 +20,8 @@ type SSHStdinserverConnecter struct {
TransportOpenCommand []string `mapstructure:"transport_open_command"` TransportOpenCommand []string `mapstructure:"transport_open_command"`
SSHCommand string `mapstructure:"ssh_command"` SSHCommand string `mapstructure:"ssh_command"`
Options []string Options []string
DialTimeout string `mapstructure:"dial_timeout"`
dialTimeout time.Duration
} }
func parseSSHStdinserverConnecter(i map[string]interface{}) (c *SSHStdinserverConnecter, err error) { func parseSSHStdinserverConnecter(i map[string]interface{}) (c *SSHStdinserverConnecter, err error) {
@ -29,6 +32,15 @@ func parseSSHStdinserverConnecter(i map[string]interface{}) (c *SSHStdinserverCo
return nil, err return nil, err
} }
if c.DialTimeout != "" {
c.dialTimeout, err = time.ParseDuration(c.DialTimeout)
if err != nil {
return nil, errors.Wrap(err, "cannot parse dial_timeout")
}
} else {
c.dialTimeout = 10 * time.Second
}
// TODO assert fields are filled // TODO assert fields are filled
return return
@ -38,9 +50,15 @@ func (c *SSHStdinserverConnecter) Connect() (rwc io.ReadWriteCloser, err error)
var endpoint netssh.Endpoint var endpoint netssh.Endpoint
if err = copier.Copy(&endpoint, c); err != nil { if err = copier.Copy(&endpoint, c); err != nil {
return return nil, errors.WithStack(err)
} }
if rwc, err = netssh.Dial(context.TODO(), endpoint); err != nil { var dialCtx context.Context
dialCtx, dialCancel := context.WithTimeout(context.TODO(), c.dialTimeout) // context.TODO tied to error handling below
defer dialCancel()
if rwc, err = netssh.Dial(dialCtx, endpoint); err != nil {
if err == context.DeadlineExceeded {
err = errors.Errorf("dial_timeout of %s exceeded", c.dialTimeout)
}
err = errors.WithStack(err) err = errors.WithStack(err)
return return
} }

View File

@ -19,7 +19,13 @@ Developers should consult the git commit log or GitHub issue tracker.
* Make sure to understand the meaning bookmarks have for :ref:`maximum replication downtime <replication-downtime>`. * Make sure to understand the meaning bookmarks have for :ref:`maximum replication downtime <replication-downtime>`.
* Example: :sampleconf:`pullbackup/productionhost.yml` * Example: :sampleconf:`pullbackup/productionhost.yml`
* |break| :commit:`ccd062e`: both sides of a replication setup must be updated and restarted. Otherwise the connecting side will hang and not time out. * |break| :commit:`ccd062e`: ``ssh+stdinserver`` transport: changed protocol requires daemon restart on both sides
* The delicate procedure of talking to the serving-side zrepl daemon via the stdinserver proxy command now has better error handling.
* This includes handshakes between client+proxy and client + remote daemo, which is not implemented in previous versions of zrepl.
* The connecting side will therefore time out, with the message ``dial_timeout of 10s exceeded``.
* Both sides of a replication setup must be updated and restarted. Otherwise the connecting side will hang and not time out.
* |break_config| :commit:`2bfcfa5`: first outlet in ``global.logging`` is now used for logging meta-errors, for example problems encountered when writing to other outlets. * |break_config| :commit:`2bfcfa5`: first outlet in ``global.logging`` is now used for logging meta-errors, for example problems encountered when writing to other outlets.
* |feature| :issue:`10`: ``zrepl control status`` subcommand * |feature| :issue:`10`: ``zrepl control status`` subcommand

View File

@ -85,8 +85,9 @@ Connect Mode
user: root user: root
port: 22 port: 22
identity_file: /etc/zrepl/ssh/identity identity_file: /etc/zrepl/ssh/identity
options: # optional options: # optional, default [], `-o` arguments passed to ssh
- "Compression=on" - "Compression=on"
dial_timeout: # optional, default 10s, max time.Duration until initial handshake is completed
The connecting zrepl daemon The connecting zrepl daemon