fix panic by ndeloof · Pull Request #13562 · docker/compose

Yea, I was looking because otherwise calling start multiple times would append a new listener to the global var, and start a new goroutine

numberOfWatches.Add(int64(len(d.stream.Paths)))

So yeah, probably could be merged into NewWatcher then; looks like that requires an interface change 🤔

type Notify interface {
// Start watching the paths set at init time
Start() error

For a more "organic" approach an alternative could also be to remove the Close function, and make Start return a "cancel" / "close" function, so that it's clear to the caller that it must be closed after, i.e. something like;

close, err := watcher.Start()
// ....
defer close()

Either way, that's an existing issue, and not something that's hit by the current code