Merge pull request #1569 from hashicorp/fix-network-port-collisions

Fix network port collisions when asking for dyn ports
This commit is contained in:
Diptanu Choudhury 2016-08-11 16:19:45 -07:00 committed by GitHub
commit 01e08a64ee
1 changed files with 3 additions and 2 deletions

View File

@ -214,7 +214,7 @@ func (idx *NetworkIndex) AssignNetwork(ask *NetworkResource) (out *NetworkResour
var dynPorts []int
var dynErr error
dynPorts, dynErr = getDynamicPortsStochastic(used, ask)
if err == nil {
if dynErr == nil {
goto BUILD_OFFER
}
@ -271,8 +271,9 @@ func getDynamicPortsPrecise(nodeUsed Bitmap, ask *NetworkResource) ([]int, error
return nil, fmt.Errorf("dynamic port selection failed")
}
numAvailable := len(availablePorts)
for i := 0; i < numDyn; i++ {
j := rand.Intn(numDyn)
j := rand.Intn(numAvailable)
availablePorts[i], availablePorts[j] = availablePorts[j], availablePorts[i]
}