File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ func New(backend istanbul.Backend, config *istanbul.Config) Engine {
3939 config : config ,
4040 address : backend .Address (),
4141 state : StateAcceptRequest ,
42+ handlerWg : new (sync.WaitGroup ),
4243 logger : log .New ("address" , backend .Address ()),
4344 backend : backend ,
4445 backlogs : make (map [istanbul.Validator ]* prque.Prque ),
@@ -75,7 +76,8 @@ type core struct {
7576 backlogs map [istanbul.Validator ]* prque.Prque
7677 backlogsMu * sync.Mutex
7778
78- current * roundState
79+ current * roundState
80+ handlerWg * sync.WaitGroup
7981
8082 roundChangeSet * roundChangeSet
8183 roundChangeTimer * time.Timer
Original file line number Diff line number Diff line change @@ -38,7 +38,9 @@ func (c *core) Start() error {
3838func (c * core ) Stop () error {
3939 c .stopTimer ()
4040 c .unsubscribeEvents ()
41- c .current = nil
41+
42+ // Make sure the handler goroutine exits
43+ c .handlerWg .Wait ()
4244 return nil
4345}
4446
@@ -69,6 +71,14 @@ func (c *core) unsubscribeEvents() {
6971}
7072
7173func (c * core ) handleEvents () {
74+ // Clear state
75+ defer func () {
76+ c .current = nil
77+ c .handlerWg .Done ()
78+ }()
79+
80+ c .handlerWg .Add (1 )
81+
7282 for {
7383 select {
7484 case event , ok := <- c .events .Chan ():
You can’t perform that action at this time.
0 commit comments