Skip to content

mempool: CListMempool.Flush invokes a read-lock meanwhile it performs write/mutating operations; inadequately tested because there will be data races too #2443

@odeke-em

Description

@odeke-em

Bug Report

Noticed in a code audit that this code is erroneously invoking a read-lock meanwhile it performs write/mutating operations

func (mem *CListMempool) Flush() {
mem.updateMtx.RLock()
defer mem.updateMtx.RUnlock()
mem.txsBytes.Store(0)
mem.cache.Reset()
mem.removeAllTxs()
}

which also means that this mempool implementation is not properly tested because it clearly invokes mutating code here

func (mem *CListMempool) removeAllTxs() {
for e := mem.txs.Front(); e != nil; e = e.Next() {
mem.txs.Remove(e)
e.DetachPrev()
}
mem.txsMap.Range(func(key, _ interface{}) bool {
mem.txsMap.Delete(key)
mem.invokeRemoveTxOnReactor(key.(types.TxKey))
return true
})
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmempool

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions