Hold lock while accessing mutable variable, but release before sending on chan

This commit is contained in:
Paul Bellamy committed 2015-06-16 13:06:14 +01:00
1 parent 7a106aeb5f
commit 048261c921
1 file changed
+5 -2
+5 -2
View File
@@ -235,15 +235,18 @@ func (zone *ZoneDb) DomainLookupInaddr(inaddr string) (res []ZoneRecord, err err
func (zone *ZoneDb) startUpdatingName(name string) {
if zone.refreshInterval > 0 {
zone.mx.Lock()
// check if we should enqueue a refresh request for this name
n := zone.getNameSet(defaultRemoteIdent).getName(name, true)
now := zone.clock.Now()
zone.mx.Unlock() // Don't hold the lock while talking to the SchedQueue
if n.lastRefreshTime.IsZero() {
now := zone.clock.Now()
n.lastRefreshTime = now
zone.mx.Unlock()
Debug.Printf("[zonedb] Creating new immediate refresh request for '%s'", name)
zone.refreshScheds.Add(func() time.Time { return zone.updater(name) }, now)
} else {
zone.mx.Unlock()
}
}
}