From 2dde817682c8b9aa291b5d9d0a326302e8a4d154 Mon Sep 17 00:00:00 2001 From: badgersrus <43809877+badgersrus@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:10:38 +0400 Subject: [PATCH] manually rollback failed tx as its causing idle connections (#1881) --- go/host/storage/hostdb/hostdb.go | 7 +++++++ go/host/storage/storage.go | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/go/host/storage/hostdb/hostdb.go b/go/host/storage/hostdb/hostdb.go index d63e63e1e8..64b23d222f 100644 --- a/go/host/storage/hostdb/hostdb.go +++ b/go/host/storage/hostdb/hostdb.go @@ -59,3 +59,10 @@ func (b *dbTransaction) Write() error { } return nil } + +func (b *dbTransaction) Rollback() error { + if err := b.tx.Rollback(); err != nil { + return fmt.Errorf("failed to rollback host transaction. Cause: %w", err) + } + return nil +} diff --git a/go/host/storage/storage.go b/go/host/storage/storage.go index 9737c9164e..a3a7cba39f 100644 --- a/go/host/storage/storage.go +++ b/go/host/storage/storage.go @@ -34,6 +34,9 @@ func (s *storageImpl) AddBatch(batch *common.ExtBatch) error { } if err := hostdb.AddBatch(dbtx, s.db.GetSQLStatement(), batch); err != nil { + if err := dbtx.Rollback(); err != nil { + return err + } return fmt.Errorf("could not add batch to host. Cause: %w", err) } @@ -56,6 +59,9 @@ func (s *storageImpl) AddRollup(rollup *common.ExtRollup, metadata *common.Publi } if err := hostdb.AddRollup(dbtx, s.db.GetSQLStatement(), rollup, metadata, block); err != nil { + if err := dbtx.Rollback(); err != nil { + return err + } return fmt.Errorf("could not add rollup to host. Cause: %w", err) } @@ -72,6 +78,9 @@ func (s *storageImpl) AddBlock(b *types.Header, rollupHash common.L2RollupHash) } if err := hostdb.AddBlock(dbtx, s.db.GetSQLStatement(), b, rollupHash); err != nil { + if err := dbtx.Rollback(); err != nil { + return err + } return fmt.Errorf("could not add block to host. Cause: %w", err) }