From 6d108924a4ad5f15721bdc808e6b6657d566b3ef Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Tue, 12 Nov 2024 11:22:27 +0000 Subject: [PATCH] fix: DB write of upsert pins in run as group Signed-off-by: Enrique Lacal --- .gitignore | 3 ++- internal/events/batch_pin_complete.go | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f716852eb..6d7e50306 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ __debug* containerlogs .vscode/*.log .idea -doc-site/site \ No newline at end of file +doc-site/site +doc-site/venv diff --git a/internal/events/batch_pin_complete.go b/internal/events/batch_pin_complete.go index 7dccbe5cb..ee99cb4ac 100644 --- a/internal/events/batch_pin_complete.go +++ b/internal/events/batch_pin_complete.go @@ -1,4 +1,4 @@ -// Copyright © 2023 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -125,10 +125,15 @@ func (em *eventManager) persistContexts(ctx context.Context, batchPin *blockchai log.L(ctx).Warnf("Batch insert of pins failed - assuming replay and performing upserts: %s", err) // Fall back to an upsert + // Use a different context to not re-use DB TX from a group run + // We only get here if it fails so this would never work in the same DB TX + upsertCtx, cancel := context.WithCancel(ctx) + defer cancel() for _, pin := range pins { - if err := em.database.UpsertPin(ctx, pin); err != nil { + if err := em.database.UpsertPin(upsertCtx, pin); err != nil { return err } } + return nil }