From 2731d787c2e5d1e5d50afe8d78e709bf8ff4de83 Mon Sep 17 00:00:00 2001 From: Alessio Date: Sat, 14 Sep 2024 16:01:28 -0700 Subject: [PATCH] Prevent failed SaveNotification transaction from locking the database --- pkg/persistence/notification_queries.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/persistence/notification_queries.go b/pkg/persistence/notification_queries.go index 554f86b..baa873c 100644 --- a/pkg/persistence/notification_queries.go +++ b/pkg/persistence/notification_queries.go @@ -9,6 +9,13 @@ import ( func (p Profile) SaveNotification(n Notification) { tx, err := p.DB.Beginx() + defer func() { + if r := recover(); r != nil { + tx.Rollback() + panic(r) // Re-raise the panic + } + }() + if err != nil { panic(err) }