Skip to content

Commit

Permalink
transition to disconnected upon scheduler ERROR events
Browse files Browse the repository at this point in the history
  • Loading branch information
James DeFelice committed Apr 24, 2017
1 parent bd7142a commit 5df42ce
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions api/v1/lib/httpcli/httpsched/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package httpsched

import (
"errors"
"fmt"
"log"
"net/http"
"sync"
Expand Down Expand Up @@ -106,6 +107,13 @@ func disconnectedFn(state *state) stateFn {
return disconnectedFn
}

transitionToDisconnected := func() {
state.m.Lock()
defer state.m.Unlock()
state.fn = disconnectedFn
_ = stateResp.Close() // swallow any error here
}

// wrap the response: any errors processing the subscription stream should result in a
// transition to a disconnected state ASAP.
state.resp = &mesos.ResponseWrapper{
Expand All @@ -115,10 +123,17 @@ func disconnectedFn(state *state) stateFn {
return func(u encoding.Unmarshaler) (err error) {
err = decoder(u)
if err != nil {
state.m.Lock()
defer state.m.Unlock()
state.fn = disconnectedFn
_ = stateResp.Close() // swallow any error here
transitionToDisconnected()
return
}
switch e := u.(type) {
case (*scheduler.Event):
if e.GetType() == scheduler.Event_ERROR {
transitionToDisconnected()
}
default:
err = httpcli.ProtocolError(
fmt.Sprintf("unexpected object on subscription event stream", e))
}
return
}
Expand Down

0 comments on commit 5df42ce

Please sign in to comment.