mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
rafthttp: write StatusOK before start streaming
This commit is contained in:
parent
e9235002f7
commit
84ceefbffc
@ -156,16 +156,17 @@ func (h *streamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
sw := newStreamWriter(from, term)
|
||||||
w.(http.Flusher).Flush()
|
|
||||||
|
|
||||||
sw := newStreamWriter(w.(WriteFlusher), from, term)
|
|
||||||
err = p.attachStream(sw)
|
err = p.attachStream(sw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("rafthttp: %v", err)
|
log.Printf("rafthttp: %v", err)
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.(http.Flusher).Flush()
|
||||||
|
go sw.handle(w.(WriteFlusher))
|
||||||
<-sw.stopNotify()
|
<-sw.stopNotify()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,14 +162,13 @@ type streamWriter struct {
|
|||||||
|
|
||||||
// newStreamServer starts and returns a new started stream server.
|
// newStreamServer starts and returns a new started stream server.
|
||||||
// The caller should call stop when finished, to shut it down.
|
// The caller should call stop when finished, to shut it down.
|
||||||
func newStreamWriter(w WriteFlusher, to types.ID, term uint64) *streamWriter {
|
func newStreamWriter(to types.ID, term uint64) *streamWriter {
|
||||||
s := &streamWriter{
|
s := &streamWriter{
|
||||||
to: to,
|
to: to,
|
||||||
term: term,
|
term: term,
|
||||||
q: make(chan []raftpb.Entry, streamBufSize),
|
q: make(chan []raftpb.Entry, streamBufSize),
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
}
|
}
|
||||||
go s.handle(w)
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user