Skip to content

Commit 74d8f15

Browse files
authored
Merge pull request #147 from getamis/bug/istanbul-crash-in-integration-test
consensus/istanbul: clear state in handler goroutine and stop core synchronuously
2 parents 868570b + 6cbd190 commit 74d8f15

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

consensus/istanbul/core/core.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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

consensus/istanbul/core/handler.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ func (c *core) Start() error {
3838
func (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

7173
func (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():

0 commit comments

Comments
 (0)