Skip to content

Commit

Permalink
Merge pull request etcd-io#3759 from yichengq/rafthttp-unreachable
Browse files Browse the repository at this point in the history
rafthttp: mark unreachable on unexpected response
  • Loading branch information
yichengq committed Oct 29, 2015
2 parents 1944893 + 84d7825 commit 1b3d913
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
15 changes: 9 additions & 6 deletions rafthttp/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,17 @@ func (p *pipeline) post(data []byte) (err error) {
resp.Body.Close()

err = checkPostResponse(resp, b, req, p.to)
// errMemberRemoved is a critical error since a removed member should
// always be stopped. So we use reportCriticalError to report it to errorc.
if err == errMemberRemoved {
reportCriticalError(err, p.errorc)
return nil
if err != nil {
p.picker.unreachable(u)
// errMemberRemoved is a critical error since a removed member should
// always be stopped. So we use reportCriticalError to report it to errorc.
if err == errMemberRemoved {
reportCriticalError(err, p.errorc)
}
return err
}

return err
return nil
}

// waitSchedule waits other goroutines to be scheduled for a while
Expand Down
5 changes: 5 additions & 0 deletions rafthttp/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,14 @@ func (cr *streamReader) dial(t streamType) (io.ReadCloser, error) {
lv := semver.Must(semver.NewVersion(version.Version))
if compareMajorMinorVersion(rv, lv) == -1 && !checkStreamSupport(rv, t) {
resp.Body.Close()
cr.picker.unreachable(u)
return nil, errUnsupportedStreamType
}

switch resp.StatusCode {
case http.StatusGone:
resp.Body.Close()
cr.picker.unreachable(u)
err := fmt.Errorf("the member has been permanently removed from the cluster")
select {
case cr.errorc <- err:
Expand All @@ -408,6 +410,7 @@ func (cr *streamReader) dial(t streamType) (io.ReadCloser, error) {
return resp.Body, nil
case http.StatusNotFound:
resp.Body.Close()
cr.picker.unreachable(u)
return nil, fmt.Errorf("remote member %s could not recognize local member", cr.remote)
case http.StatusPreconditionFailed:
b, err := ioutil.ReadAll(resp.Body)
Expand All @@ -416,6 +419,7 @@ func (cr *streamReader) dial(t streamType) (io.ReadCloser, error) {
return nil, err
}
resp.Body.Close()
cr.picker.unreachable(u)

switch strings.TrimSuffix(string(b), "\n") {
case errIncompatibleVersion.Error():
Expand All @@ -430,6 +434,7 @@ func (cr *streamReader) dial(t streamType) (io.ReadCloser, error) {
}
default:
resp.Body.Close()
cr.picker.unreachable(u)
return nil, fmt.Errorf("unhandled http status %d", resp.StatusCode)
}
}
Expand Down
1 change: 1 addition & 0 deletions rafthttp/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func TestTransportUpdate(t *testing.T) {
func TestTransportErrorc(t *testing.T) {
errorc := make(chan error, 1)
tr := &Transport{
Raft: &fakeRaft{},
LeaderStats: stats.NewLeaderStats(""),
ErrorC: errorc,
streamRt: newRespRoundTripper(http.StatusForbidden, nil),
Expand Down

0 comments on commit 1b3d913

Please sign in to comment.