Skip to content

Commit 13ea52b

Browse files
committed
fix(mempool): data race in clist_mempool during async recheck
+ fixed callback invocation in unsync_local_client during CheckTxAsync
1 parent 99b244d commit 13ea52b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

abci/client/unsync_local_client.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@ func (app *unsyncLocalClient) CheckTxAsync(ctx context.Context, req *types.Reque
4747
reqres := NewReqRes(types.ToRequestCheckTx(req))
4848

4949
go func() {
50-
res, err := app.Application.CheckTx(ctx, req)
50+
res, _ := app.Application.CheckTx(ctx, req)
51+
reqres.Response = types.ToResponseCheckTx(res)
5152

52-
if err != nil {
53-
// reqres.Response = types.ToResponseException(err.Error()) // don't think this is needed
54-
return
53+
if app.Callback != nil {
54+
app.Callback(reqres.Request, reqres.Response)
5555
}
56-
57-
reqres.Response = types.ToResponseCheckTx(res)
5856
reqres.InvokeCallback()
5957
}()
6058

mempool/clist_mempool.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ type CListMempool struct {
5555

5656
logger log.Logger
5757
metrics *Metrics
58+
59+
recheckCbMux cmtsync.Mutex
5860
}
5961

6062
var _ Mempool = &CListMempool{}
@@ -478,6 +480,8 @@ func (mem *CListMempool) resCbFirstTime(
478480
// The case where the app checks the tx for the first time is handled by the
479481
// resCbFirstTime callback.
480482
func (mem *CListMempool) resCbRecheck(tx types.Tx, res *abci.ResponseCheckTx) {
483+
mem.recheckCbMux.Lock()
484+
defer mem.recheckCbMux.Unlock()
481485
// Check whether tx is still in the list of transactions that can be rechecked.
482486
if !mem.recheck.findNextEntryMatching(&tx) {
483487
// Reached the end of the list and didn't find a matching tx; rechecking has finished.

0 commit comments

Comments
 (0)