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

Commit

Permalink
fix deadlock + race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVorick committed Jul 21, 2016
1 parent 6eee259 commit e6d0bec
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions modules/consensus/consensusset.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ func New(gateway modules.Gateway, persistDir string) (*ConsensusSet, error) {
gateway.RegisterRPC("SendBlk", cs.rpcSendBlk)
gateway.RegisterConnectCall("SendBlocks", cs.threadedReceiveBlocks)
cs.tg.OnStop(func() {
cs.mu.Lock()
defer cs.mu.Unlock()

cs.gateway.UnregisterRPC("SendBlocks")
cs.gateway.UnregisterRPC("RelayBlock")
cs.gateway.UnregisterRPC("RelayHeader")
Expand Down Expand Up @@ -205,6 +202,12 @@ func (cs *ConsensusSet) Close() error {
return err
}

// Shouldn't be necessary when `Stop` call is complete, but currently
// `Stop` will not pause all ongoing processes, meaning a lock is needed
// during the rest of shutdown.
cs.mu.Lock()
defer cs.mu.Unlock()

var errs []error
if err := cs.db.Close(); err != nil {
errs = append(errs, fmt.Errorf("db.Close failed: %v", err))
Expand Down

0 comments on commit e6d0bec

Please sign in to comment.