From 607b52897321e31cea7b62c820d40710bcf1315b Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 25 Feb 2015 16:11:58 +0000 Subject: [PATCH] Copy connections before sending, to avoid a deadlock --- router/gossip.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/router/gossip.go b/router/gossip.go index 5c374221..1e50b707 100644 --- a/router/gossip.go +++ b/router/gossip.go @@ -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 {