From b4b5036dfb306985849ecebf1095ae3bd4233a0a Mon Sep 17 00:00:00 2001 From: James Phillips Date: Fri, 2 Jun 2017 20:53:20 -0700 Subject: [PATCH] Adds back the port shuffle on agent start retries. --- command/agent/testagent.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/command/agent/testagent.go b/command/agent/testagent.go index 3c80049661..0090462edf 100644 --- a/command/agent/testagent.go +++ b/command/agent/testagent.go @@ -120,11 +120,9 @@ func (a *TestAgent) Start() *TestAgent { } id := UniqueID() - // since the ports are written into the data files we pick random ports - // only once and try a number of times to start with them. - pickRandomPorts(a.Config) - for i := 10; i >= 0; i-- { + pickRandomPorts(a.Config) + // write the keyring if a.Key != "" { writeKey := func(key, filename string) { @@ -163,6 +161,16 @@ func (a *TestAgent) Start() *TestAgent { fmt.Println(id, a.Name, "retrying in", wait) time.Sleep(wait) } + + // Clean out the data dir if we are responsible for it before we + // try again, since the old ports may have gotten written to + // the data dir, such as in the Raft configuration. + if a.DataDir != "" { + if err := os.RemoveAll(a.DataDir); err != nil { + fmt.Println(id, a.Name, "Error resetting data dir:", err) + runtime.Goexit() + } + } } if !a.NoInitialSync { a.Agent.StartSync()