etcdserver: time out when readStateC is blocking

Otherwise, it will block forever when the server is overloaded.

Fix https://github.com/coreos/etcd/issues/6891.
This commit is contained in:
Gyu-Ho Lee 2016-12-05 15:34:46 -08:00
parent 2509e7ad2c
commit 3fd1d951f8
No known key found for this signature in database
GPG Key ID: 1DDD39C7EB70C24C

View File

@ -135,6 +135,7 @@ func (r *raftNode) start(rh *raftReadyHandler) {
r.applyc = make(chan apply)
r.stopped = make(chan struct{})
r.done = make(chan struct{})
internalTimeout := time.Second
go func() {
defer r.onStop()
@ -167,6 +168,8 @@ func (r *raftNode) start(rh *raftReadyHandler) {
if len(rd.ReadStates) != 0 {
select {
case r.readStateC <- rd.ReadStates[len(rd.ReadStates)-1]:
case <-time.After(internalTimeout):
plog.Warningf("timed out sending read state")
case <-r.stopped:
return
}