diff options
author | bojie <a1346494@gmail.com> | 2018-11-12 09:15:21 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:18 +0800 |
commit | 25eeb82e487b4200b179928f0b78353fea3915c3 (patch) | |
tree | 0195d6858ec99c06f8f5ae3c66d5f3f3ca4af1dd | |
parent | 70eec5f6d181a79201ab96e1d982d07c41d26cdc (diff) | |
download | go-tangerine-25eeb82e487b4200b179928f0b78353fea3915c3.tar go-tangerine-25eeb82e487b4200b179928f0b78353fea3915c3.tar.gz go-tangerine-25eeb82e487b4200b179928f0b78353fea3915c3.tar.bz2 go-tangerine-25eeb82e487b4200b179928f0b78353fea3915c3.tar.lz go-tangerine-25eeb82e487b4200b179928f0b78353fea3915c3.tar.xz go-tangerine-25eeb82e487b4200b179928f0b78353fea3915c3.tar.zst go-tangerine-25eeb82e487b4200b179928f0b78353fea3915c3.zip |
app: bug fix (#7)
Add notify mutex to prevent missing chain issue while concurrent
appending with same slice.
-rw-r--r-- | dex/app.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/dex/app.go b/dex/app.go index 7d2165118..d0d911e86 100644 --- a/dex/app.go +++ b/dex/app.go @@ -51,6 +51,7 @@ type DexconApp struct { chainLocksInitMu sync.Mutex chainLocks map[uint32]*sync.RWMutex + notifyMu sync.Mutex notifyChan sync.Map chainLatestRoot sync.Map } @@ -79,6 +80,9 @@ func NewDexconApp(txPool *core.TxPool, blockchain *core.BlockChain, gov *DexconG } func (d *DexconApp) addNotify(height uint64) <-chan uint64 { + d.notifyMu.Lock() + defer d.notifyMu.Unlock() + result := make(chan uint64) v, ok := d.notifyChan.Load(height) if ok { @@ -92,6 +96,9 @@ func (d *DexconApp) addNotify(height uint64) <-chan uint64 { } func (d *DexconApp) notify(height uint64) { + d.notifyMu.Lock() + defer d.notifyMu.Unlock() + d.notifyChan.Range(func(key, value interface{}) bool { h := key.(uint64) n := value.(*notify) |