hashicorp / hcat

Hashicorp Configuration and Templating library (hcat, pronounced hashicat)
Mozilla Public License 2.0
95 stars 12 forks source link

Add locks to a couple watcher methods #100

Closed lornasong closed 2 years ago

lornasong commented 2 years ago

In CTS the notifiersFor() was causing a race condition detected by the go race detector which points to the usage of w.tracker in notifersFor():

WARNING: DATA RACE
Read at 0x00c000268488 by goroutine 46:
  github.com/hashicorp/hcat.(*tracker).notifiersFor()
      /Users/lornasong/go/src/github.com/hashicorp/consul-terraform-sync/vendor/github.com/hashicorp/hcat/watcher.go:685 +0x9c
      ...
Previous write at 0x00c000268488 by goroutine 45:
  github.com/hashicorp/hcat.(*tracker).sweep()
      /Users/lornasong/go/src/github.com/hashicorp/consul-terraform-sync/vendor/github.com/hashicorp/hcat/watcher.go:736 +0x1e4

Also pre-emptively added locks to complete() since it also accesses w.tracker.