device: only allocate peer queues once
This serves two purposes. First, it makes repeatedly stopping then starting a peer cheaper. Second, it prevents a data race observed accessing the queues. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
parent
cae090d116
commit
78ebce6932
|
@ -179,10 +179,10 @@ func (peer *Peer) Start() {
|
||||||
peer.handshake.lastSentHandshake = time.Now().Add(-(RekeyTimeout + time.Second))
|
peer.handshake.lastSentHandshake = time.Now().Add(-(RekeyTimeout + time.Second))
|
||||||
peer.handshake.mutex.Unlock()
|
peer.handshake.mutex.Unlock()
|
||||||
|
|
||||||
// prepare queues
|
// prepare queues (once)
|
||||||
|
if peer.queue.outbound == nil {
|
||||||
peer.queue.outbound = newAutodrainingOutboundQueue(device)
|
peer.queue.outbound = newAutodrainingOutboundQueue(device)
|
||||||
peer.queue.inbound = newAutodrainingInboundQueue(device)
|
peer.queue.inbound = newAutodrainingInboundQueue(device)
|
||||||
if peer.queue.staged == nil {
|
|
||||||
peer.queue.staged = make(chan *QueueOutboundElement, QueueStagedSize)
|
peer.queue.staged = make(chan *QueueOutboundElement, QueueStagedSize)
|
||||||
}
|
}
|
||||||
peer.device.queue.encryption.wg.Add(1) // keep encryption queue open for our writes
|
peer.device.queue.encryption.wg.Add(1) // keep encryption queue open for our writes
|
||||||
|
|
Loading…
Reference in a new issue