Fix the broadcast bug introduced by for loop deferencing to the last element (for loop variable is just a temp pointer to the element)

pull/20/head
Rongjian Lan 6 years ago
parent 35d69bfb2c
commit da45cdeef5
  1. 2
      consensus/consensus.go
  2. BIN
      harmony-benchmark
  3. 5
      p2p/peer.go

@ -146,8 +146,8 @@ func NewConsensus(ip, port, ShardID string, peers []p2p.Peer, leader p2p.Peer) C
if consensus.IsLeader {
consensus.ReadySignal = make(chan int)
// TODO: why do we need to do go rountine here.
// send a signal to indicate it's ready to run consensus
// this is a goroutine because go channel without buffer will block
go func() {
consensus.ReadySignal <- 1
}()

Binary file not shown.

@ -32,11 +32,12 @@ func BroadcastMessage(peers []Peer, msg []byte) {
var wg sync.WaitGroup
wg.Add(len(peers))
for _, peer := range peers {
// send(peer.Ip, peer.Port, content)
peerCopy := peer
go func() {
defer wg.Done()
send(peer.Ip, peer.Port, content)
send(peerCopy.Ip, peerCopy.Port, content)
}()
}
wg.Wait()

Loading…
Cancel
Save