Skip to content

Commit

Permalink
Protect identity use or creation by mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
anjmao committed Apr 23, 2020
1 parent 601869c commit 1583231
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions identity/selector/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package selector

import (
"sync"

"github.com/mysteriumnetwork/node/identity"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
Expand All @@ -30,6 +32,7 @@ type IdentityRegistry interface {
}

type handler struct {
mu sync.Mutex
manager identity.Manager
registry IdentityRegistry
cache identity.IdentityCacheInterface
Expand All @@ -52,6 +55,9 @@ func NewHandler(
}

func (h *handler) UseOrCreate(address, passphrase string) (id identity.Identity, err error) {
h.mu.Lock()
defer h.mu.Unlock()

if len(address) > 0 {
log.Debug().Msg("Using existing identity")
return h.useExisting(address, passphrase)
Expand Down

0 comments on commit 1583231

Please sign in to comment.