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

Export ConnectToProxy() for some backoff stage #21

Merged

Conversation

liut
Copy link
Contributor

@liut liut commented Jun 3, 2020

  • Export ConnectToProxy() can support backoff for keepalive, like github.com/cenkalti/backoff, code example:
import "time"
import "github.com/cenkalti/backoff"

func expBackoff() backoff.BackOff {
	b := backoff.NewExponentialBackOff()
	b.InitialInterval = 500 * time.Millisecond
	b.Multiplier = 1.5
	b.MaxInterval = 60 * time.Second
	b.MaxElapsedTime = 0 // never stop

	return b
}

// Retry ...
func Retry(o backoff.Operation) error {
	return backoff.RetryNotify(o, expBackoff(), func(err error, d time.Duration) {
		log.Print("retry", "err", err, "d", d)
	})
}

main() {
	Retry(func() error {
		return remotedialer.ConnectToProxy(context.Background(), uri, headers, 
			func(string, string) bool { return true }, nil, nil)
	})
}
  • Add some comments

@ibuildthecloud ibuildthecloud merged commit d8b45d3 into rancher:master Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants