mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #2108 from yichengq/305
rafthttp: write StatusOK before start streaming
This commit is contained in:
commit
4b6fa2d24f
@ -156,16 +156,17 @@ func (h *streamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.(http.Flusher).Flush()
|
||||
|
||||
sw := newStreamWriter(w.(WriteFlusher), from, term)
|
||||
sw := newStreamWriter(from, term)
|
||||
err = p.attachStream(sw)
|
||||
if err != nil {
|
||||
log.Printf("rafthttp: %v", err)
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.(http.Flusher).Flush()
|
||||
go sw.handle(w.(WriteFlusher))
|
||||
<-sw.stopNotify()
|
||||
}
|
||||
|
||||
|
@ -162,14 +162,13 @@ type streamWriter struct {
|
||||
|
||||
// newStreamServer starts and returns a new started stream server.
|
||||
// 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{
|
||||
to: to,
|
||||
term: term,
|
||||
q: make(chan []raftpb.Entry, streamBufSize),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
go s.handle(w)
|
||||
return s
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user