Skip to content

Commit

Permalink
Added dial timeout to etcdutil
Browse files Browse the repository at this point in the history
  • Loading branch information
thrawn01 committed Aug 7, 2018
1 parent f5cc693 commit 3df4eb4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions etcdutil/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/mailgun/holster"
"github.com/pkg/errors"
"google.golang.org/grpc/grpclog"
"time"
)

const (
Expand Down Expand Up @@ -59,6 +60,18 @@ func NewEtcdConfig(cfg *etcd.Config) (*etcd.Config, error) {
holster.SetDefault(&tlsKeyFile, os.Getenv("ETCD3_TLS_KEY"), ifExists(pathToKey))
holster.SetDefault(&tlsCaFile, os.Getenv("ETCD3_CA"), ifExists(pathToCA))

// Default to 5 second timeout, else connections hang indefinitely
holster.SetDefault(&cfg.DialTimeout, time.Second*5)
// Or if the user provided a timeout
if timeout := os.Getenv("ETCD3_DIAL_TIMEOUT"); timeout != "" {
duration, err := time.ParseDuration(timeout)
if err != nil {
return nil, errors.Errorf(
"ETCD3_DIAL_TIMEOUT='%s' is not a duration (1m|15s|24h): %s", timeout, err)
}
cfg.DialTimeout = duration
}

// If the CA file was provided
if tlsCaFile != "" {
holster.SetDefault(&cfg.TLS, &tls.Config{})
Expand Down

0 comments on commit 3df4eb4

Please sign in to comment.