Skip to content

Commit b30109d

Browse files
gluk256zelig
authored andcommitted
swarm/pss: mutex lifecycle fixed (ethereum#19045)
1 parent 8771fbf commit b30109d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

swarm/pss/protocol.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ func ToP2pMsg(msg []byte) (p2p.Msg, error) {
228228
// to link the peer to.
229229
// The key must exist in the pss store prior to adding the peer.
230230
func (p *Protocol) AddPeer(peer *p2p.Peer, topic Topic, asymmetric bool, key string) (p2p.MsgReadWriter, error) {
231+
var ok bool
231232
rw := &PssReadWriter{
232233
Pss: p.Pss,
233234
rw: make(chan p2p.Msg),
@@ -242,19 +243,21 @@ func (p *Protocol) AddPeer(peer *p2p.Peer, topic Topic, asymmetric bool, key str
242243
}
243244
if asymmetric {
244245
p.Pss.pubKeyPoolMu.Lock()
245-
if _, ok := p.Pss.pubKeyPool[key]; !ok {
246+
_, ok = p.Pss.pubKeyPool[key]
247+
p.Pss.pubKeyPoolMu.Unlock()
248+
if !ok {
246249
return nil, fmt.Errorf("asym key does not exist: %s", key)
247250
}
248-
p.Pss.pubKeyPoolMu.Unlock()
249251
p.RWPoolMu.Lock()
250252
p.pubKeyRWPool[key] = rw
251253
p.RWPoolMu.Unlock()
252254
} else {
253255
p.Pss.symKeyPoolMu.Lock()
254-
if _, ok := p.Pss.symKeyPool[key]; !ok {
256+
_, ok = p.Pss.symKeyPool[key]
257+
p.Pss.symKeyPoolMu.Unlock()
258+
if !ok {
255259
return nil, fmt.Errorf("symkey does not exist: %s", key)
256260
}
257-
p.Pss.symKeyPoolMu.Unlock()
258261
p.RWPoolMu.Lock()
259262
p.symKeyRWPool[key] = rw
260263
p.RWPoolMu.Unlock()

0 commit comments

Comments
 (0)