fix peer stop channel problem

pull/820/head
Xiang Li 2013-07-07 19:58:01 -07:00
parent 46dd6bbd81
commit e045441f52
1 changed files with 12 additions and 2 deletions

14
peer.go
View File

@ -32,7 +32,7 @@ func newPeer(server *Server, name string, heartbeatTimeout time.Duration) *Peer
return &Peer{
server: server,
name: name,
stopChan: make(chan bool),
stopChan: make(chan bool, 1),
heartbeatTimeout: heartbeatTimeout,
}
}
@ -90,7 +90,17 @@ func (p *Peer) startHeartbeat() {
// Stops the peer heartbeat.
func (p *Peer) stopHeartbeat() {
p.stopChan <- true
// here is a problem
// the previous stop is no buffer leader may get blocked
// when heartbeat returns at line 132
// I make the channel with 1 buffer
// and try to panic here
select {
case p.stopChan <- true:
default:
panic("[" + p.server.Name() + "] cannot stop [" + p.Name() + "] heartbeat")
}
}
//--------------------------------------