haproxytech / haproxy-consul-connect

HaProxy Connector for Consul Connect. Enables Service Mesh with Consul and HaProxy using TLS and Consul Discovery
Apache License 2.0
95 stars 20 forks source link

MEDIUM: watcher: fix race condition & plumbing stop for test #42

Open amelhusic opened 4 years ago

amelhusic commented 4 years ago

this fix is related to: https://github.com/haproxytech/haproxy-consul-connect/issues/10

ShimmerGlass commented 4 years ago

This will not stop the goroutines from running once the Watcher is stopped. One way to do that is to add a check in the infinite loops to stop them when the Watcher is stopped:

for {
  select {
    case <-w.shutdownCh:
      return
    default:
  }

  // work
}

Additionally, I'd prefer exposing a Stop() method rather than the chan directly.

amelhusic commented 4 years ago

I applied your recommendations.

aiharos commented 4 years ago

Please recheck and give a thumbs up for mergeing.