Skip to content
This repository has been archived by the owner on Nov 18, 2017. It is now read-only.

Commit

Permalink
fsm: update where stop chans are created
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Deare committed Aug 25, 2016
1 parent 368c49e commit 483611d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions fsm/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ func NewGovernorFSM(config *Config) (SingleLeaderFSM, error) {
memberChans: make(map[uint64]chan MemberUpdate),
leaderChans: make(map[uint64]chan LeaderUpdate),

stopc: make(chan struct{}),
stoppedc: make(chan struct{}),

observationLock: sync.Mutex{},

syncTicker: time.Tick(500 * time.Millisecond),
Expand Down Expand Up @@ -192,6 +189,9 @@ func NewGovernorFSM(config *Config) (SingleLeaderFSM, error) {
}

func (f *fsm) start() error {
f.stopc = make(chan struct{})
f.stoppedc = make(chan struct{})

if err := f.raft.Start(); err != nil {
return errors.Wrap(err, "Error starting raft")
}
Expand Down Expand Up @@ -445,12 +445,14 @@ func (f *fsm) Destroy() error {
return errors.Wrap(err, "Error destroying raft")
}

close(f.stopc)
if f.stopc != nil {
close(f.stopc)

select {
case <-f.stoppedc:
case <-time.Tick(10 * time.Second):
return ErrorTimedOutCleanup
select {
case <-f.stoppedc:
case <-time.Tick(10 * time.Second):
return ErrorTimedOutCleanup
}
}

return nil
Expand Down

0 comments on commit 483611d

Please sign in to comment.