Commit fd0f3d7c authored by suyanlong's avatar suyanlong

Fix RandRouterPort function

parent a00052d2
Pipeline #8421 failed with stages
...@@ -133,13 +133,15 @@ func (p *PortMap) RandRouterPort() Port { ...@@ -133,13 +133,15 @@ func (p *PortMap) RandRouterPort() Port {
p.rw.RLock() p.rw.RLock()
defer p.rw.RUnlock() defer p.rw.RUnlock()
l := len(p.peerPort) l := len(p.peerPort)
i := rand.Intn(l) if l > 0 {
j := 0 i := rand.Intn(l)
for _, pt := range p.peerPort { j := 0
if i == j { for _, pt := range p.peerPort {
return pt if i == j {
return pt
}
j++
} }
j++
} }
return nil return nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment