diff --git a/pkg/storage/replica.go b/pkg/storage/replica.go index fe57074e14da..9534e4cc9da8 100644 --- a/pkg/storage/replica.go +++ b/pkg/storage/replica.go @@ -2589,9 +2589,6 @@ func (r *Replica) tryExecuteWriteBatch( log.Event(ctx, "applied timestamp cache") ch, tryAbandon, undoQuotaAcquisition, pErr := r.propose(ctx, lease, ba, endCmds, spans) - if pErr != nil { - return nil, pErr, proposalNoRetry - } defer func() { // NB: We may be double free-ing here, consider the following cases: // - The request was evaluated and the command resulted in an error, but a @@ -2602,6 +2599,9 @@ func (r *Replica) tryExecuteWriteBatch( undoQuotaAcquisition() } }() + if pErr != nil { + return nil, pErr, proposalNoRetry + } // After the command is proposed to Raft, invoking endCmds.done is now the // responsibility of processRaftCommand.