Skip to content

Commit

Permalink
Recover from unexpected EOF with API Server
Browse files Browse the repository at this point in the history
Signed-off-by: Waldemar Quevedo <[email protected]>
  • Loading branch information
wallyqs committed Jun 26, 2018
1 parent 969f40e commit 989458e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ func (c *Controller) watch(watchVersion string) (<-chan *Event, <-chan error) {
for {
ev, st, err := pollEvent(decoder)
if err != nil {
if err == io.EOF { // apiserver will close stream periodically
// API Server will close stream periodically so schedule a reconnect,
// also recover in connection was broken for some reason.
if err == io.EOF || err == io.ErrUnexpectedEOF {
c.logger.Info("apiserver closed watch stream, retrying after 5s...")
time.Sleep(5 * time.Second)
break
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ func pollEvent(decoder *json.Decoder) (*Event, *metav1.Status, error) {
re := &rawEvent{}
err := decoder.Decode(re)
if err != nil {
if err == io.EOF {
if err == io.EOF || err == io.ErrUnexpectedEOF {
return nil, nil, err
}

return nil, nil, fmt.Errorf("fail to decode raw event from apiserver (%v)", err)
}

Expand Down

0 comments on commit 989458e

Please sign in to comment.