Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix client backoff #537

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion client/client_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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, "")
Expand Down