summaryrefslogtreecommitdiffhomepage
path: root/device/peer.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josh@tailscale.com>2021-02-09 09:08:17 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2021-02-09 18:33:48 +0100
commit78ebce69324e241d462d624cae389396db9dbd94 (patch)
treea31bea51761748d4ce4af4741254d08e8d37b5cb /device/peer.go
parentcae090d116d4aa61494f5951a9d6ab6902017dce (diff)
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>
Diffstat (limited to 'device/peer.go')
-rw-r--r--device/peer.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/device/peer.go b/device/peer.go
index 96481ee..222c74f 100644
--- a/device/peer.go
+++ b/device/peer.go
@@ -179,10 +179,10 @@ func (peer *Peer) Start() {
peer.handshake.lastSentHandshake = time.Now().Add(-(RekeyTimeout + time.Second))
peer.handshake.mutex.Unlock()
- // prepare queues
- peer.queue.outbound = newAutodrainingOutboundQueue(device)
- peer.queue.inbound = newAutodrainingInboundQueue(device)
- if peer.queue.staged == nil {
+ // prepare queues (once)
+ if peer.queue.outbound == nil {
+ peer.queue.outbound = newAutodrainingOutboundQueue(device)
+ peer.queue.inbound = newAutodrainingInboundQueue(device)
peer.queue.staged = make(chan *QueueOutboundElement, QueueStagedSize)
}
peer.device.queue.encryption.wg.Add(1) // keep encryption queue open for our writes