Skip to content

Commit

Permalink
prevent race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
czerwonk committed Nov 11, 2017
1 parent a001ccf commit 6726f90
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions gcloud/record_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ type recordUpdater struct {
}

func (u *recordUpdater) updateRecordSet(zone string, rec *dns.ResourceRecordSet, datas []string) (bool, error) {
if u.limit >= 0 && atomic.LoadInt64(&u.counter) >= u.limit {
if reflect.DeepEqual(rec.Rrdatas, datas) {
return false, nil
}

if reflect.DeepEqual(rec.Rrdatas, datas) {
count := atomic.AddInt64(&u.counter, 1)
if u.limit >= 0 && count > u.limit {
return false, nil
}

Expand All @@ -33,7 +34,6 @@ func (u *recordUpdater) updateRecordSet(zone string, rec *dns.ResourceRecordSet,
}

if u.dryRun {
atomic.AddInt64(&u.counter, 1)
return true, nil
}

Expand All @@ -51,6 +51,5 @@ func (u *recordUpdater) updateRecordSet(zone string, rec *dns.ResourceRecordSet,
return false, err
}

atomic.AddInt64(&u.counter, 1)
return true, nil
}

0 comments on commit 6726f90

Please sign in to comment.