Skip to content

Commit d3d2167

Browse files
authored
fix(mempool): lock/unlock before iterating consumers (#1067)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent b8ab1a3 commit d3d2167

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

mempool/mempool.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,14 @@ func (m *Mempool) removeTransactionByIndex(txIdx int) bool {
338338
m.metrics.txsInMempool.Dec()
339339
m.metrics.mempoolBytes.Sub(float64(len(tx.Cbor)))
340340
// Update consumer indexes to reflect removed TX
341+
m.consumersMutex.Lock()
341342
for _, consumer := range m.consumers {
342343
// Decrement consumer index if the consumer has reached the removed TX
343344
if consumer.nextTxIdx > txIdx {
344345
consumer.nextTxIdx--
345346
}
346347
}
348+
m.consumersMutex.Unlock()
347349
// Generate event
348350
m.eventBus.Publish(
349351
RemoveTransactionEventType,

0 commit comments

Comments
 (0)