From 2e2baf28ea052845c62ddc0b2be21b0808558cf9 Mon Sep 17 00:00:00 2001 From: Janos Guljas Date: Mon, 25 Feb 2019 13:49:16 +0100 Subject: [PATCH] swarm/pss: fix a data race on HandshakeController.keyC --- swarm/pss/handshake.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/swarm/pss/handshake.go b/swarm/pss/handshake.go index ad0d7352ea..bd84ef874f 100644 --- a/swarm/pss/handshake.go +++ b/swarm/pss/handshake.go @@ -106,6 +106,7 @@ func NewHandshakeParams() *HandshakeParams { type HandshakeController struct { pss *Pss keyC map[string]chan []string // adds a channel to report when a handshake succeeds + keyCMu sync.Mutex // protects keyC map lock sync.Mutex symKeyRequestTimeout time.Duration symKeyExpiryTimeout time.Duration @@ -442,6 +443,8 @@ func (ctl *HandshakeController) sendKey(pubkeyid string, topic *Topic, keycount // Enables callback for keys received from a key exchange request func (ctl *HandshakeController) alertHandshake(pubkeyid string, symkeys []string) chan []string { + ctl.keyCMu.Lock() + defer ctl.keyCMu.Unlock() if len(symkeys) > 0 { if _, ok := ctl.keyC[pubkeyid]; ok { ctl.keyC[pubkeyid] <- symkeys