Merge pull request #6434 from alml/silent-watcher-close

Ignore errors after StreamWatcher is closed
This commit is contained in:
Rohit Jnagal 2015-04-06 13:52:11 -07:00
commit 0e10b2a842

View File

@ -76,6 +76,13 @@ func (sw *StreamWatcher) Stop() {
}
}
// stopping returns true if Stop() was called previously.
func (sw *StreamWatcher) stopping() bool {
sw.Lock()
defer sw.Unlock()
return sw.stopped
}
// receive reads result from the decoder in a loop and sends down the result channel.
func (sw *StreamWatcher) receive() {
defer close(sw.result)
@ -84,6 +91,10 @@ func (sw *StreamWatcher) receive() {
for {
action, obj, err := sw.source.Decode()
if err != nil {
// Ignore expected error.
if sw.stopping() {
return
}
switch err {
case io.EOF:
// watch closed normally