diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-07-20 15:22:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-20 15:22:49 -0700 |
commit | 58839cefb50e56ae5b157b37e9814ae83ceee70b (patch) | |
tree | 5de966481678096fc9567f74f96673b34a65127c /vendor/github.com/hashicorp/memberlist/memberlist.go | |
parent | e2f4492eadb5d3c58606b1fdd5774b63a07c236a (diff) | |
download | chat-58839cefb50e56ae5b157b37e9814ae83ceee70b.tar.gz chat-58839cefb50e56ae5b157b37e9814ae83ceee70b.tar.bz2 chat-58839cefb50e56ae5b157b37e9814ae83ceee70b.zip |
Upgrading server dependancies (#6984)
Diffstat (limited to 'vendor/github.com/hashicorp/memberlist/memberlist.go')
-rw-r--r-- | vendor/github.com/hashicorp/memberlist/memberlist.go | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/vendor/github.com/hashicorp/memberlist/memberlist.go b/vendor/github.com/hashicorp/memberlist/memberlist.go index e4b0d7347..9ea195cfc 100644 --- a/vendor/github.com/hashicorp/memberlist/memberlist.go +++ b/vendor/github.com/hashicorp/memberlist/memberlist.go @@ -113,14 +113,43 @@ func newMemberlist(conf *Config) (*Memberlist, error) { BindPort: conf.BindPort, Logger: logger, } - nt, err := NewNetTransport(nc) + + // See comment below for details about the retry in here. + makeNetRetry := func(limit int) (*NetTransport, error) { + for try := 0; try < limit; try++ { + nt, err := NewNetTransport(nc) + if err == nil { + return nt, nil + } + + if strings.Contains(err.Error(), "address already in use") { + logger.Printf("[DEBUG] Got bind error: %v", err) + continue + } + } + + return nil, fmt.Errorf("ran out of tries to obtain an address") + } + + // The dynamic bind port operation is inherently racy because + // even though we are using the kernel to find a port for us, we + // are attempting to bind multiple protocols (and potentially + // multiple addresses) with the same port number. We build in a + // few retries here since this often gets transient errors in + // busy unit tests. + limit := 1 + if conf.BindPort == 0 { + limit = 10 + } + + nt, err := makeNetRetry(limit) if err != nil { return nil, fmt.Errorf("Could not set up network transport: %v", err) } - if conf.BindPort == 0 { port := nt.GetAutoBindPort() conf.BindPort = port + conf.AdvertisePort = port logger.Printf("[DEBUG] Using dynamic bind port %d", port) } transport = nt |