Skip to content

Commit

Permalink
Nate's fix on my request introduced a race condition. Fix it.
Browse files Browse the repository at this point in the history
  • Loading branch information
jameinel committed Apr 12, 2016
1 parent dd9828e commit cd2420f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion utils/stringforwarder/stringforwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,17 @@ func (f *StringForwarder) Stop() uint64 {
// closes started to signal that it has begun, and will clean itself up when
// done is closed.
func (f *StringForwarder) loop(started chan struct{}, callback func(string)) {
// Grab a copy of done so we can notice it is closed, even though
// StringForwarder.Stop() will set it to nil.
f.mu.Lock()
done := f.done
f.mu.Unlock()
close(started)
for {
select {
case msg := <-f.messages:
callback(msg)
case <-f.done:
case <-done:
return
}
}
Expand Down

0 comments on commit cd2420f

Please sign in to comment.