haproxy-consul-connect icon indicating copy to clipboard operation
haproxy-consul-connect copied to clipboard

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

Open amelhusic opened this issue 5 years ago • 4 comments

amelhusic avatar Apr 27 '20 23:04 amelhusic

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

amelhusic avatar Apr 28 '20 09:04 amelhusic

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.

ShimmerGlass avatar May 11 '20 13:05 ShimmerGlass

I applied your recommendations.

amelhusic avatar May 14 '20 15:05 amelhusic

Please recheck and give a thumbs up for mergeing.

aiharos avatar Aug 24 '20 13:08 aiharos