Skip to content

Commit 413a77c

Browse files
committed
fix: Update list of watchers serially to avoid a data race
1 parent 8f6e9ad commit 413a77c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

internal/generator/generator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ func (g *generator) generateFromEvents() {
190190
}
191191

192192
g.wg.Add(1)
193+
watcher := make(chan *docker.APIEvents, 100)
194+
watchers = append(watchers, watcher)
193195

194-
go func(cfg config.Config, watcher chan *docker.APIEvents) {
196+
go func(cfg config.Config) {
195197
defer g.wg.Done()
196-
watchers = append(watchers, watcher)
197-
198198
debouncedChan := newDebounceChannel(watcher, cfg.Wait)
199199
for range debouncedChan {
200200
containers, err := g.getContainers()
@@ -210,7 +210,7 @@ func (g *generator) generateFromEvents() {
210210
g.runNotifyCmd(cfg)
211211
g.sendSignalToContainer(cfg)
212212
}
213-
}(cfg, make(chan *docker.APIEvents, 100))
213+
}(cfg)
214214
}
215215

216216
// maintains docker client connection and passes events to watchers

0 commit comments

Comments
 (0)