@@ -150,10 +150,9 @@ func (n *Node) ReportRaftComms() {
150150 if ! glog .V (3 ) {
151151 return
152152 }
153- ticker := time .NewTicker (time .Second )
154- defer ticker .Stop ()
153+ ticker := time .Tick (time .Second )
155154
156- for range ticker . C {
155+ for range ticker {
157156 out := atomic .SwapInt64 (& n .heartbeatsOut , 0 )
158157 in := atomic .SwapInt64 (& n .heartbeatsIn , 0 )
159158 glog .Infof ("RaftComm: [%#x] Heartbeats out: %d, in: %d" , n .Id , out , in )
@@ -401,11 +400,10 @@ func (n *Node) streamMessages(to uint64, s *stream) {
401400 // Let's set the deadline to 10s because if we increase it, then it takes longer to recover from
402401 // a partition and get a new leader.
403402 deadline := time .Now ().Add (10 * time .Second )
404- ticker := time .NewTicker (time .Second )
405- defer ticker .Stop ()
403+ ticker := time .Tick (time .Second )
406404
407405 var logged int
408- for range ticker . C { // Don't do this in an busy-wait loop, use a ticker.
406+ for range ticker { // Don't do this in a busy-wait loop, use a ticker.
409407 // doSendMessage would block doing a stream. So, time.Now().After is
410408 // only there to avoid a busy-wait.
411409 if err := n .doSendMessage (to , s .msgCh ); err != nil {
@@ -460,11 +458,8 @@ func (n *Node) doSendMessage(to uint64, msgCh chan []byte) error {
460458
461459 ctx = mc .Context ()
462460
463- fastTick := time .NewTicker (5 * time .Second )
464- defer fastTick .Stop ()
465-
466- ticker := time .NewTicker (3 * time .Minute )
467- defer ticker .Stop ()
461+ fastTick := time .Tick (5 * time .Second )
462+ ticker := time .Tick (3 * time .Minute )
468463
469464 for {
470465 select {
@@ -495,7 +490,7 @@ func (n *Node) doSendMessage(to uint64, msgCh chan []byte) error {
495490 // RAFT would automatically retry.
496491 return err
497492 }
498- case <- fastTick . C :
493+ case <- fastTick :
499494 // We use this ticker, because during network partitions, mc.Send is
500495 // unable to actually send packets, and also does not complain about
501496 // them. We could have potentially used the separately tracked
@@ -512,7 +507,7 @@ func (n *Node) doSendMessage(to uint64, msgCh chan []byte) error {
512507 pool .SetUnhealthy ()
513508 return errors .Wrapf (err , "while calling IsPeer %x" , to )
514509 }
515- case <- ticker . C :
510+ case <- ticker :
516511 if lastPackets == packets {
517512 span .AddEvent (fmt .Sprintf ("No activity for a while [Packets == %d]. Closing connection." , packets ))
518513 return mc .CloseSend ()
0 commit comments