@@ -99,16 +99,24 @@ func (chain *chainImpl) Start() {
99
99
// consensus.Chain interface.
100
100
func (chain * chainImpl ) Halt () {
101
101
select {
102
- case <- chain .haltChan :
103
- // This construct is useful because it allows Halt() to be called
104
- // multiple times (by a single thread) w/o panicking. Recal that a
105
- // receive from a closed channel returns (the zero value) immediately.
106
- logger .Warningf ("[channel: %s] Halting of chain requested again" , chain .support .ChainID ())
102
+ case <- chain .startChan :
103
+ // chain finished starting, so we can halt it
104
+ select {
105
+ case <- chain .haltChan :
106
+ // This construct is useful because it allows Halt() to be called
107
+ // multiple times (by a single thread) w/o panicking. Recal that a
108
+ // receive from a closed channel returns (the zero value) immediately.
109
+ logger .Warningf ("[channel: %s] Halting of chain requested again" , chain .support .ChainID ())
110
+ default :
111
+ logger .Criticalf ("[channel: %s] Halting of chain requested" , chain .support .ChainID ())
112
+ close (chain .haltChan )
113
+ chain .closeKafkaObjects () // Also close the producer and the consumer
114
+ logger .Debugf ("[channel: %s] Closed the haltChan" , chain .support .ChainID ())
115
+ }
107
116
default :
108
- logger .Criticalf ("[channel: %s] Halting of chain requested" , chain .support .ChainID ())
109
- close (chain .haltChan )
110
- chain .closeKafkaObjects () // Also close the producer and the consumer
111
- logger .Debugf ("[channel: %s] Closed the haltChan" , chain .support .ChainID ())
117
+ logger .Warningf ("[channel: %s] Waiting for chain to finish starting before halting" , chain .support .ChainID ())
118
+ <- chain .startChan
119
+ chain .Halt ()
112
120
}
113
121
}
114
122
@@ -476,8 +484,14 @@ func sendConnectMessage(retryOptions localconfig.Retry, exitChan chan struct{},
476
484
477
485
retryMsg := "Attempting to post the CONNECT message..."
478
486
postConnect := newRetryProcess (retryOptions , exitChan , channel , retryMsg , func () error {
479
- _ , _ , err := producer .SendMessage (message )
480
- return err
487
+ select {
488
+ case <- exitChan :
489
+ logger .Debugf ("[channel: %s] Consenter for channel exiting, aborting retry" , channel )
490
+ return nil
491
+ default :
492
+ _ , _ , err := producer .SendMessage (message )
493
+ return err
494
+ }
481
495
})
482
496
483
497
return postConnect .retry ()
0 commit comments