optimisation: stop GossipSender on send error
This commit is contained in:
1 parent
486eb740b5
commit
99b7fbbc71
1 file changed
+15
-7
+15
-7
@@ -67,13 +67,21 @@ func (s *GossipSender) run(stop <-chan struct{}, more <-chan struct{}, flush <-c
|
|||||||
case <-stop:
|
case <-stop:
|
||||||
return
|
return
|
||||||
case <-more:
|
case <-more:
|
||||||
sent = s.deliver(stop) || sent
|
sentSomething, err := s.deliver(stop)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sent = sent || sentSomething
|
||||||
case ch := <-flush: // for testing
|
case ch := <-flush: // for testing
|
||||||
// send anything pending, then reply back whether we sent
|
// send anything pending, then reply back whether we sent
|
||||||
// anything since previous flush
|
// anything since previous flush
|
||||||
select {
|
select {
|
||||||
case <-more:
|
case <-more:
|
||||||
sent = s.deliver(stop) || sent
|
sentSomething, err := s.deliver(stop)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sent = sent || sentSomething
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
ch <- sent
|
ch <- sent
|
||||||
@@ -82,7 +90,7 @@ func (s *GossipSender) run(stop <-chan struct{}, more <-chan struct{}, flush <-c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GossipSender) deliver(stop <-chan struct{}) bool {
|
func (s *GossipSender) deliver(stop <-chan struct{}) (bool, error) {
|
||||||
sent := false
|
sent := false
|
||||||
// We must not hold our lock when sending, since that would block
|
// We must not hold our lock when sending, since that would block
|
||||||
// the callers of Send/Broadcast while we are stuck waiting for
|
// the callers of Send/Broadcast while we are stuck waiting for
|
||||||
@@ -91,16 +99,16 @@ func (s *GossipSender) deliver(stop <-chan struct{}) bool {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-stop:
|
case <-stop:
|
||||||
return sent
|
return sent, nil
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
data, makeProtocolMsg := s.pick()
|
data, makeProtocolMsg := s.pick()
|
||||||
if data == nil {
|
if data == nil {
|
||||||
return sent
|
return sent, nil
|
||||||
}
|
}
|
||||||
for _, msg := range data.Encode() {
|
for _, msg := range data.Encode() {
|
||||||
if s.sender.SendProtocolMsg(makeProtocolMsg(msg)) != nil {
|
if err := s.sender.SendProtocolMsg(makeProtocolMsg(msg)); err != nil {
|
||||||
break
|
return sent, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sent = true
|
sent = true
|
||||||
|
|||||||
Reference in new issue
Block a user