Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/runtime/txpool: Abort runtime in case it times out during checks #4563

Merged
merged 1 commit into from
Mar 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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