From c8e88d383e5fa1f2c667bc43c92bdc5cd4d7d614 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 10 Dec 2013 09:05:26 -0600 Subject: [PATCH] Correct issue with pushing address messages. The code to send an address messages in batches was previously clearing all addresses from the existing message after queueing it to be sent. Since the message is a pointer, this means it was removing the addresses from the same message which might not have already been sent yet (from another goroutine) which led to a race. This commit modifies the code to create a new address message for each batch as intended. Fixes #58. --- peer.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/peer.go b/peer.go index ad102d6b..aa9439e9 100644 --- a/peer.go +++ b/peer.go @@ -773,7 +773,11 @@ func (p *peer) pushAddrMsg(addresses []*btcwire.NetAddress) error { // Split into multiple messages as needed. if numAdded > 0 && numAdded%btcwire.MaxAddrPerMsg == 0 { p.QueueMessage(msg, nil) - msg.ClearAddresses() + + // NOTE: This needs to be a new address message and not + // simply call ClearAddresses since the message is a + // pointer and queueing it does not make a copy. + msg = btcwire.NewMsgAddr() } }