Commit 69d45c15 authored by Sebastian Stammler's avatar Sebastian Stammler Committed by GitHub

txmgr: fix racy access to nonces slice in TestQueue_Send with mutex (#10016)

parent c9b3ecb8
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"slices" "slices"
"sync"
"testing" "testing"
"time" "time"
...@@ -181,10 +182,15 @@ func TestQueue_Send(t *testing.T) { ...@@ -181,10 +182,15 @@ func TestQueue_Send(t *testing.T) {
} }
// track the nonces, and return any expected errors from tx sending // track the nonces, and return any expected errors from tx sending
var nonces []uint64 var (
nonces []uint64
nonceMu sync.Mutex
)
sendTx := func(ctx context.Context, tx *types.Transaction) error { sendTx := func(ctx context.Context, tx *types.Transaction) error {
index := int(tx.Data()[0]) index := int(tx.Data()[0])
nonceMu.Lock()
nonces = append(nonces, tx.Nonce()) nonces = append(nonces, tx.Nonce())
nonceMu.Unlock()
var testTx *testTx var testTx *testTx
if index < len(test.txs) { if index < len(test.txs) {
testTx = &test.txs[index] testTx = &test.txs[index]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment