A continuation of HomeBox the inventory and organization system built for the Home User
fix: roll back thumbnail transaction on all errors to prevent DB lockups (#1761)
Márton Marázd33e9b8e6212
diff --git a/backend/internal/data/repo/repo_item_attachments.go b/backend/internal/data/repo/repo_item_attachments.goindex 06f0a96d..d33cfb91 100644--- a/backend/internal/data/repo/repo_item_attachments.go+++ b/backend/internal/data/repo/repo_item_attachments.go@@ -625,8 +625,11 @@ func (r *AttachmentRepo) CreateThumbnail(ctx context.Context, groupId, attachmenlog.Debug().Msg("starting thumbnail creation")tx, err := r.db.Tx(ctx)if err != nil {- return nil+ return err}+ // Always end the transaction, whatever the return path+ // After a successful Commit this is a no-op (returns sql.ErrTxDone)+ defer func() { _ = tx.Rollback() }()// If there is an error during file creation rollback the databasedefer func() {if v := recover(); v != nil {@@ -861,7 +864,7 @@ func (r *AttachmentRepo) CreateThumbnail(ctx context.Context, groupId, attachmenlog.Debug().Msg("finishing thumbnail creation transaction")if err := tx.Commit(); err != nil {log.Err(err).Msg("failed to commit transaction")- return nil+ return err}return nil}