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.
This commit is contained in:
parent
9e44506fdc
commit
c8e88d383e
1 changed files with 5 additions and 1 deletions
6
peer.go
6
peer.go
|
@ -773,7 +773,11 @@ func (p *peer) pushAddrMsg(addresses []*btcwire.NetAddress) error {
|
||||||
// Split into multiple messages as needed.
|
// Split into multiple messages as needed.
|
||||||
if numAdded > 0 && numAdded%btcwire.MaxAddrPerMsg == 0 {
|
if numAdded > 0 && numAdded%btcwire.MaxAddrPerMsg == 0 {
|
||||||
p.QueueMessage(msg, nil)
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue