From 64a89d8a46398cf7b2da060e95b9286e9f7e9ca2 Mon Sep 17 00:00:00 2001 From: Abdul Rabbani Date: Mon, 13 Jun 2022 12:15:18 -0400 Subject: [PATCH] Fix datarace condition By creating local variables within each goroutine. --- .gitignore | 1 + pkg/beaconclient/databasewrite.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 90badf2..bca777b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ temp/* pkg/beaconclient/ssz-data/ *.test ipld-eth-beacon-indexer.log +config/local.ipld-eth-beacon-indexer-config.json diff --git a/pkg/beaconclient/databasewrite.go b/pkg/beaconclient/databasewrite.go index b8f8aaf..93b4d58 100644 --- a/pkg/beaconclient/databasewrite.go +++ b/pkg/beaconclient/databasewrite.go @@ -545,7 +545,6 @@ func IsSlotInDb(ctx context.Context, db sql.Database, slot string, blockRoot str var ( isInBeaconState bool isInSignedBeaconBlock bool - err error ) errG, _ := errgroup.WithContext(context.Background()) errG.Go(func() error { @@ -553,6 +552,7 @@ func IsSlotInDb(ctx context.Context, db sql.Database, slot string, blockRoot str case <-ctx.Done(): return nil default: + var err error isInBeaconState, err = checkSlotAndRoot(db, CheckBeaconStateStmt, slot, stateRoot) if err != nil { loghelper.LogError(err).Error("Unable to check if the slot and stateroot exist in eth_beacon.state") @@ -565,6 +565,7 @@ func IsSlotInDb(ctx context.Context, db sql.Database, slot string, blockRoot str case <-ctx.Done(): return nil default: + var err error isInSignedBeaconBlock, err = checkSlotAndRoot(db, CheckSignedBeaconBlockStmt, slot, blockRoot) if err != nil { loghelper.LogError(err).Error("Unable to check if the slot and block_root exist in eth_beacon.signed_block")