mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #6073 from heyitsanthony/rafthttp-close-stream
rafthttp: close http socket when pipeline handler gets a raft error
This commit is contained in:
commit
59ac42ff38
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user