mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-27 13:58:05 +00:00
Merge pull request #1411 from nspcc-dev/fix-panic-in-cli-tests
consensus: wait goroutine to finish on Shutdown
This commit is contained in:
commit
a9f5fe424d
1 changed files with 8 additions and 3 deletions
|
@ -76,6 +76,7 @@ type service struct {
|
||||||
// goroutine.
|
// goroutine.
|
||||||
started *atomic.Bool
|
started *atomic.Bool
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
|
finished chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config is a configuration for consensus services.
|
// Config is a configuration for consensus services.
|
||||||
|
@ -119,6 +120,7 @@ func NewService(cfg Config) (Service, error) {
|
||||||
network: cfg.Chain.GetConfig().Magic,
|
network: cfg.Chain.GetConfig().Magic,
|
||||||
started: atomic.NewBool(false),
|
started: atomic.NewBool(false),
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
|
finished: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Wallet == nil {
|
if cfg.Wallet == nil {
|
||||||
|
@ -197,14 +199,16 @@ func (s *service) Start() {
|
||||||
// Shutdown implements Service interface.
|
// Shutdown implements Service interface.
|
||||||
func (s *service) Shutdown() {
|
func (s *service) Shutdown() {
|
||||||
close(s.quit)
|
close(s.quit)
|
||||||
|
<-s.finished
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) eventLoop() {
|
func (s *service) eventLoop() {
|
||||||
|
events:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-s.quit:
|
case <-s.quit:
|
||||||
s.dbft.Timer.Stop()
|
s.dbft.Timer.Stop()
|
||||||
return
|
break events
|
||||||
case <-s.dbft.Timer.C():
|
case <-s.dbft.Timer.C():
|
||||||
hv := s.dbft.Timer.HV()
|
hv := s.dbft.Timer.HV()
|
||||||
s.log.Debug("timer fired",
|
s.log.Debug("timer fired",
|
||||||
|
@ -250,6 +254,7 @@ func (s *service) eventLoop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
close(s.finished)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) handleChainBlock(b *coreb.Block) {
|
func (s *service) handleChainBlock(b *coreb.Block) {
|
||||||
|
|
Loading…
Reference in a new issue