Copy connections before sending, to avoid a deadlock

This commit is contained in:
Bryan Boreham committed 2015-02-25 16:11:58 +00:00
1 parent c74ffe6369
commit 607b528973
1 file changed
+6 -1
+6 -1
View File
@@ -117,9 +117,14 @@ func deliverGossip(channel *GossipChannel, srcName PeerName, _ []byte, dec *gob.
func (c *GossipChannel) SendGossipMsg(buf []byte) {
protocolMsg := c.gossipMsg(buf)
// Copy the connections so we don't hold a lock
connections := make([]Connection, 0)
c.ourself.ForEachConnection(func(_ PeerName, conn Connection) {
conn.(ProtocolSender).SendProtocolMsg(protocolMsg)
connections = append(connections, conn)
})
for _, conn := range connections {
conn.(ProtocolSender).SendProtocolMsg(protocolMsg)
}
}
func (c *GossipChannel) gossipMsg(buf []byte) ProtocolMsg {