Skip to content
/ etcd Public
forked from etcd-io/etcd

Commit

Permalink
Merge pull request etcd-io#6073 from heyitsanthony/rafthttp-close-stream
Browse files Browse the repository at this point in the history
rafthttp: close http socket when pipeline handler gets a raft error
  • Loading branch information
Anthony Romano authored Aug 1, 2016
2 parents a2715e3 + 911dcc9 commit 59ac42f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions rafthttp/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ func (h *pipelineHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
default:
plog.Warningf("failed to process raft message (%v)", err)
http.Error(w, "error processing raft message", http.StatusInternalServerError)
w.(http.Flusher).Flush()
// disconnect the http stream
panic(err)
}
return
}
Expand Down
13 changes: 12 additions & 1 deletion rafthttp/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,18 @@ func TestServeRaftPrefix(t *testing.T) {
req.Header.Set("X-Server-Version", version.Version)
rw := httptest.NewRecorder()
h := newPipelineHandler(NewNopTransporter(), tt.p, types.ID(0))
h.ServeHTTP(rw, req)

// goroutine because the handler panics to disconnect on raft error
donec := make(chan struct{})
go func() {
defer func() {
recover()
close(donec)
}()
h.ServeHTTP(rw, req)
}()
<-donec

if rw.Code != tt.wcode {
t.Errorf("#%d: got code=%d, want %d", i, rw.Code, tt.wcode)
}
Expand Down

0 comments on commit 59ac42f

Please sign in to comment.