Skip to content

Commit

Permalink
Fix a race in recorder Start()/Stop()
Browse files Browse the repository at this point in the history
If a recorder is Stop()ed before he finished Start()ing,
he may not have created the channels used by Stop().
Those should be initialized at instanciation time, really.
  • Loading branch information
bpineau committed Apr 23, 2018
1 parent 9a64ab0 commit 29d69be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/recorder/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func New(config *config.KfConfig, events event.Notifier) *Listener {
config: config,
events: events,
actives: activeFiles{},
stopch: make(chan struct{}),
donech: make(chan struct{}),
}
}

Expand All @@ -58,8 +60,6 @@ func (w *Listener) Start() *Listener {
go func() {
evCh := w.events.ReadChan()
gcTick := time.NewTicker(w.config.ResyncIntv * 2)
w.stopch = make(chan struct{})
w.donech = make(chan struct{})
defer gcTick.Stop()
defer close(w.donech)

Expand Down
2 changes: 2 additions & 0 deletions pkg/recorder/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func TestFailingFSRecorder(t *testing.T) {
// back to normal operations
rec.Stop() // just to flush ongoing ops before switch filesystem
appFs = afero.NewMemMapFs()
rec.stopch = make(chan struct{})
rec.donech = make(chan struct{})
rec.Start()
evt.Send(newNotif(event.Upsert, "foo2"))
rec.Stop() // flush ongoing ops
Expand Down

0 comments on commit 29d69be

Please sign in to comment.