Merge pull request #2767 from ironcladlou/watch-error-handling

Log ErrUnexpectedEOF from watches as warnings
pull/6/head
bgrant0607 2014-12-05 13:43:26 -08:00
commit f95503dc2d
2 changed files with 16 additions and 3 deletions

View File

@ -19,6 +19,7 @@ package cache
import ( import (
"errors" "errors"
"fmt" "fmt"
"io"
"reflect" "reflect"
"time" "time"
@ -99,7 +100,14 @@ func (r *Reflector) listAndWatch() {
for { for {
w, err := r.listerWatcher.Watch(resourceVersion) w, err := r.listerWatcher.Watch(resourceVersion)
if err != nil { if err != nil {
glog.Errorf("failed to watch %v: %v", r.expectedType, err) switch err {
case io.EOF:
// watch closed normally
case io.ErrUnexpectedEOF:
glog.V(1).Infof("Watch for %v closed with unexpected EOF: %v", r.expectedType, err)
default:
glog.Errorf("Failed to watch %v: %v", r.expectedType, err)
}
return return
} }
if err := r.watchHandler(w, &resourceVersion); err != nil { if err := r.watchHandler(w, &resourceVersion); err != nil {
@ -167,6 +175,6 @@ func (r *Reflector) watchHandler(w watch.Interface, resourceVersion *string) err
glog.Errorf("unexpected watch close - watch lasted less than a second and no items received") glog.Errorf("unexpected watch close - watch lasted less than a second and no items received")
return errors.New("very short watch") return errors.New("very short watch")
} }
glog.V(4).Infof("watch close - %v total items received", eventCount) glog.V(4).Infof("Watch close - %v total %v items received", r.expectedType, eventCount)
return nil return nil
} }

View File

@ -84,7 +84,12 @@ func (sw *StreamWatcher) receive() {
for { for {
action, obj, err := sw.source.Decode() action, obj, err := sw.source.Decode()
if err != nil { if err != nil {
if err != io.EOF { switch err {
case io.EOF:
// watch closed normally
case io.ErrUnexpectedEOF:
glog.V(1).Infof("Unexpected EOF during watch stream event decoding: %v", err)
default:
glog.Errorf("Unable to decode an event from the watch stream: %v", err) glog.Errorf("Unable to decode an event from the watch stream: %v", err)
} }
return return