aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-02-14 12:59:02 +0800
committerGitHub <noreply@github.com>2019-02-14 12:59:02 +0800
commitc5bc98e3e0131ef35632c2b82ac6111d67611cc9 (patch)
treee9e7b15e5713d53fc808e98f2365126b7bbe67d2
parent33955365a764647b4e95eb8236eb9d54e7ceba12 (diff)
downloaddexon-consensus-c5bc98e3e0131ef35632c2b82ac6111d67611cc9.tar
dexon-consensus-c5bc98e3e0131ef35632c2b82ac6111d67611cc9.tar.gz
dexon-consensus-c5bc98e3e0131ef35632c2b82ac6111d67611cc9.tar.bz2
dexon-consensus-c5bc98e3e0131ef35632c2b82ac6111d67611cc9.tar.lz
dexon-consensus-c5bc98e3e0131ef35632c2b82ac6111d67611cc9.tar.xz
dexon-consensus-c5bc98e3e0131ef35632c2b82ac6111d67611cc9.tar.zst
dexon-consensus-c5bc98e3e0131ef35632c2b82ac6111d67611cc9.zip
core: fix closing closed channel (#445)
-rw-r--r--core/agreement.go26
1 files changed, 17 insertions, 9 deletions
diff --git a/core/agreement.go b/core/agreement.go
index 10ba354..b35100b 100644
--- a/core/agreement.go
+++ b/core/agreement.go
@@ -434,8 +434,10 @@ func (a *agreement) processVote(vote *types.Vote) error {
a.hasOutput = true
a.data.recv.ConfirmBlock(hash,
a.data.votes[vote.Period][vote.Type])
- close(a.doneChan)
- a.doneChan = nil
+ if a.doneChan != nil {
+ close(a.doneChan)
+ a.doneChan = nil
+ }
}
return nil
}
@@ -468,7 +470,10 @@ func (a *agreement) processVote(vote *types.Vote) error {
a.data.lockIter = vote.Period
}
a.fastForward <- vote.Period
- close(a.doneChan)
+ if a.doneChan != nil {
+ close(a.doneChan)
+ a.doneChan = nil
+ }
return nil
}
}
@@ -494,7 +499,10 @@ func (a *agreement) processVote(vote *types.Vote) error {
a.data.recv.PullBlocks(hashes)
}
a.fastForward <- vote.Period + 1
- close(a.doneChan)
+ if a.doneChan != nil {
+ close(a.doneChan)
+ a.doneChan = nil
+ }
return nil
}
return nil
@@ -503,13 +511,10 @@ func (a *agreement) processVote(vote *types.Vote) error {
func (a *agreement) done() <-chan struct{} {
a.lock.Lock()
defer a.lock.Unlock()
- if a.doneChan == nil {
- return closedchan
- }
- a.data.lock.Lock()
- defer a.data.lock.Unlock()
select {
case period := <-a.fastForward:
+ a.data.lock.Lock()
+ defer a.data.lock.Unlock()
if period <= a.data.period {
break
}
@@ -519,6 +524,9 @@ func (a *agreement) done() <-chan struct{} {
return closedchan
default:
}
+ if a.doneChan == nil {
+ return closedchan
+ }
return a.doneChan
}