diff --git a/client/client.go b/client/client.go index 49b62e65..0a23b7ca 100644 --- a/client/client.go +++ b/client/client.go @@ -35,7 +35,9 @@ type Config struct { Auth string KeepAlive time.Duration MaxRetryCount int + MinRetryInterval time.Duration MaxRetryInterval time.Duration + RetryJitter bool Server string Proxy string Remotes []string @@ -75,6 +77,9 @@ func NewClient(c *Config) (*Client, error) { if !strings.HasPrefix(c.Server, "http") { c.Server = "http://" + c.Server } + if c.MinRetryInterval < time.Second { + c.MinRetryInterval = 100 * time.Millisecond + } if c.MaxRetryInterval < time.Second { c.MaxRetryInterval = 5 * time.Minute } diff --git a/client/client_connect.go b/client/client_connect.go index 884c7647..35f58e92 100644 --- a/client/client_connect.go +++ b/client/client_connect.go @@ -19,7 +19,9 @@ import ( func (c *Client) connectionLoop(ctx context.Context) error { //connection loop! - b := &backoff.Backoff{Max: c.config.MaxRetryInterval} + b := &backoff.Backoff{Min: c.config.MinRetryInterval, + Max: c.config.MaxRetryInterval, + Jitter: c.config.RetryJitter} for { connected, err := c.connectionOnce(ctx) //reset backoff after successful connections diff --git a/main.go b/main.go index 01f9ca3b..a0f6ea79 100644 --- a/main.go +++ b/main.go @@ -382,9 +382,14 @@ var clientHelp = ` --max-retry-count, Maximum number of times to retry before exiting. Defaults to unlimited. + --min-retry-interval, Minimum wait time before retrying after a + disconnection. Incremented by 2x for each retry. Defaults to 100ms. + --max-retry-interval, Maximum wait time before retrying after a disconnection. Defaults to 5 minutes. + --retry-jitter, Enable jitter in the retry interval. Defaults to false. + --proxy, An optional HTTP CONNECT or SOCKS5 proxy which will be used to reach the chisel server. Authentication can be specified inside the URL. @@ -427,7 +432,9 @@ func client(args []string) { flags.StringVar(&config.Auth, "auth", "", "") flags.DurationVar(&config.KeepAlive, "keepalive", 25*time.Second, "") flags.IntVar(&config.MaxRetryCount, "max-retry-count", -1, "") + flags.DurationVar(&config.MinRetryInterval, "min-retry-interval", 0, "") flags.DurationVar(&config.MaxRetryInterval, "max-retry-interval", 0, "") + flags.BoolVar(&config.RetryJitter, "retry-jitter", false, "") flags.StringVar(&config.Proxy, "proxy", "", "") flags.StringVar(&config.TLS.CA, "tls-ca", "", "") flags.BoolVar(&config.TLS.SkipVerify, "tls-skip-verify", false, "")