Skip to content

Commit c9b01e0

Browse files
committed
libn/networkdb: SetPrimaryKey() under a write lock
(*NetworkDB).SetPrimaryKey() acquires a read lock on the NetworkDB instance. That seems sound on the surface as it is only reading from the NetworkDB struct, not mutating it. However, concurrent calls to (*memberlist.Keyring).UseKey() would get flagged by Go's race detector due to some questionable locking in its implementation. Acquire an exclusive lock in SetPrimaryKey so concurrent calls don't race each other. Signed-off-by: Cory Snider <[email protected]>
1 parent 2e25c2b commit c9b01e0

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

libnetwork/networkdb/cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ func (nDB *NetworkDB) SetKey(key []byte) {
7171
// been added apriori through SetKey
7272
func (nDB *NetworkDB) SetPrimaryKey(key []byte) {
7373
log.G(context.TODO()).Debugf("Primary Key %.5s", hex.EncodeToString(key))
74-
nDB.RLock()
75-
defer nDB.RUnlock()
74+
nDB.Lock()
75+
defer nDB.Unlock()
7676
for _, dbKey := range nDB.config.Keys {
7777
if bytes.Equal(key, dbKey) {
7878
if nDB.keyring != nil {

0 commit comments

Comments
 (0)