瀏覽代碼

Data race: Discoverer.registryLock must cover the contents of registry as well

Jakob Borg 11 年之前
父節點
當前提交
577aaf8ad6
共有 1 個文件被更改,包括 3 次插入4 次删除
  1. 3 4
      internal/discover/discover.go

+ 3 - 4
internal/discover/discover.go

@@ -340,9 +340,10 @@ func (d *Discoverer) registerDevice(addr net.Addr, device Device) bool {
 	var id protocol.DeviceID
 	copy(id[:], device.ID)
 
-	d.registryLock.RLock()
+	d.registryLock.Lock()
+	defer d.registryLock.Unlock()
+
 	current := d.filterCached(d.registry[id])
-	d.registryLock.RUnlock()
 
 	orig := current
 
@@ -372,9 +373,7 @@ func (d *Discoverer) registerDevice(addr net.Addr, device Device) bool {
 		l.Debugf("discover: register: %v -> %v", id, current)
 	}
 
-	d.registryLock.Lock()
 	d.registry[id] = current
-	d.registryLock.Unlock()
 
 	if len(current) > len(orig) {
 		addrs := make([]string, len(current))