From 68b44ccf770a488fb6efb2e55ccb587e80e1c8f7 Mon Sep 17 00:00:00 2001 From: Janos Guljas Date: Mon, 25 Feb 2019 14:26:02 +0100 Subject: [PATCH] swarm/pss: fix data races with on Pss.symKeyPool --- swarm/pss/handshake.go | 2 ++ swarm/pss/keystore.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/swarm/pss/handshake.go b/swarm/pss/handshake.go index bd84ef874f..ec3bffa30a 100644 --- a/swarm/pss/handshake.go +++ b/swarm/pss/handshake.go @@ -206,7 +206,9 @@ func (ctl *HandshakeController) updateKeys(pubkeyid string, topic *Topic, in boo limit: limit, } *keystore = append(*keystore, storekey) + ctl.pss.mx.Lock() ctl.pss.symKeyPool[*storekey.symKeyID][*topic].protected = true + ctl.pss.mx.Unlock() } for i := 0; i < len(*keystore); i++ { ctl.symKeyIndex[*(*keystore)[i].symKeyID] = &((*keystore)[i]) diff --git a/swarm/pss/keystore.go b/swarm/pss/keystore.go index 510d21bcfd..5c44cb2453 100644 --- a/swarm/pss/keystore.go +++ b/swarm/pss/keystore.go @@ -210,6 +210,8 @@ func (ks *Pss) processAsym(envelope *whisper.Envelope) (*whisper.ReceivedMessage // - it is not marked as protected // - it is not in the incoming decryption cache func (ks *Pss) cleanKeys() (count int) { + ks.mx.Lock() + defer ks.mx.Unlock() for keyid, peertopics := range ks.symKeyPool { var expiredtopics []Topic for topic, psp := range peertopics { @@ -229,10 +231,8 @@ func (ks *Pss) cleanKeys() (count int) { } } for _, topic := range expiredtopics { - ks.mx.Lock() delete(ks.symKeyPool[keyid], topic) log.Trace("symkey cleanup deletion", "symkeyid", keyid, "topic", topic, "val", ks.symKeyPool[keyid]) - ks.mx.Unlock() count++ } }