Skip to content

Commit

Permalink
Merge pull request #147 from getamis/bug/istanbul-crash-in-integratio…
Browse files Browse the repository at this point in the history
…n-test

consensus/istanbul: clear state in handler goroutine and stop core synchronuously
  • Loading branch information
alanchchen authored Sep 5, 2017
2 parents 868570b + 6cbd190 commit 74d8f15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion consensus/istanbul/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func New(backend istanbul.Backend, config *istanbul.Config) Engine {
config: config,
address: backend.Address(),
state: StateAcceptRequest,
handlerWg: new(sync.WaitGroup),
logger: log.New("address", backend.Address()),
backend: backend,
backlogs: make(map[istanbul.Validator]*prque.Prque),
Expand Down Expand Up @@ -75,7 +76,8 @@ type core struct {
backlogs map[istanbul.Validator]*prque.Prque
backlogsMu *sync.Mutex

current *roundState
current *roundState
handlerWg *sync.WaitGroup

roundChangeSet *roundChangeSet
roundChangeTimer *time.Timer
Expand Down
12 changes: 11 additions & 1 deletion consensus/istanbul/core/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func (c *core) Start() error {
func (c *core) Stop() error {
c.stopTimer()
c.unsubscribeEvents()
c.current = nil

// Make sure the handler goroutine exits
c.handlerWg.Wait()
return nil
}

Expand Down Expand Up @@ -69,6 +71,14 @@ func (c *core) unsubscribeEvents() {
}

func (c *core) handleEvents() {
// Clear state
defer func() {
c.current = nil
c.handlerWg.Done()
}()

c.handlerWg.Add(1)

for {
select {
case event, ok := <-c.events.Chan():
Expand Down

0 comments on commit 74d8f15

Please sign in to comment.