Skip to content

Commit

Permalink
mempool: release lock during app connection flush (#8986)
Browse files Browse the repository at this point in the history
A manual backport of #8984.

This case is symmetric to what we did for CheckTx calls, where we release the
mempool mutex to ensure callbacks can fire during call setup.  We also need
this behaviour for application flush, for the same reason: The caller holds the
lock by contract from the Mempool interface.

Co-authored-by: M. J. Fromberger <fromberger@interchain.io>
  • Loading branch information
tnasu and M. J. Fromberger committed Jul 13, 2023
1 parent 82bccab commit cddddc8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion mempool/v1/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,18 @@ func (txmp *TxMempool) SizeBytes() int64 { return atomic.LoadInt64(&txmp.txsByte
//
// The caller must hold an exclusive mempool lock (by calling txmp.Lock) before
// calling FlushAppConn.
func (txmp *TxMempool) FlushAppConn() error { return txmp.proxyAppConn.FlushSync() }
func (txmp *TxMempool) FlushAppConn() error {
// N.B.: We have to issue the call outside the lock so that its callback can
// fire. It's safe to do this, the flush will block until complete.
//
// We could just not require the caller to hold the lock at all, but the
// semantics of the Mempool interface require the caller to hold it, and we
// can't change that without disrupting existing use.
txmp.mtx.Unlock()
defer txmp.mtx.Lock()

return txmp.proxyAppConn.FlushSync()
}

// EnableTxsAvailable enables the mempool to trigger events when transactions
// are available on a block by block basis.
Expand Down

0 comments on commit cddddc8

Please sign in to comment.