Skip to content

Commit

Permalink
go/runtime/txpool: Abort runtime in case it times out during checks
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Mar 13, 2022
1 parent 59b92eb commit e879e2a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions .changelog/4563.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/runtime/txpool: Abort runtime in case it times out during checks
22 changes: 21 additions & 1 deletion go/runtime/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package txpool

import (
"context"
"errors"
"fmt"
"sync"
"time"
Expand All @@ -27,6 +28,8 @@ const (
checkTxTimeout = 15 * time.Second
// checkTxRetryDelay is the time to wait before queuing a check tx retry.
checkTxRetryDelay = 1 * time.Second
// abortTimeout is the maximum time the runtime can spend aborting.
abortTimeout = 5 * time.Second
)

// Config is the transaction pool configuration.
Expand Down Expand Up @@ -484,7 +487,24 @@ func (t *txPool) checkTxBatch(ctx context.Context, rr host.RichRuntime) {
rawTxBatch = append(rawTxBatch, item.Tx)
}
results, err := rr.CheckTx(checkCtx, bi.RuntimeBlock, bi.ConsensusBlock, bi.Epoch, bi.ActiveDescriptor.Executor.MaxMessages, rawTxBatch)
if err != nil {
switch {
case err == nil:
case errors.Is(err, context.Canceled):
// Context was canceled while the runtime was processing a request.
t.logger.Error("transaction batch check aborted by context, aborting runtime")

// Abort the runtime, so we can start processing the next batch.
abortCtx, cancel := context.WithTimeout(ctx, abortTimeout)
defer cancel()

if err = rr.Abort(abortCtx, false); err != nil {
t.logger.Error("failed to abort the runtime",
"err", err,
)
}

fallthrough
default:
t.logger.Warn("transaction batch check failed",
"err", err,
)
Expand Down

0 comments on commit e879e2a

Please sign in to comment.