From 2f01ec38bd86e65f8f21b688103542a700b82fa8 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 1 Oct 2026 21:55:58 +0200 Subject: [PATCH] fix: use READ COMMITTED transactions on MySQL and MariaDB (#39506) MariaDB 11.6.2+ defaults `innodb_snapshot_isolation` to `ON`, which fails REPEATABLE READ transactions with error 1020 when a row they write changed after their first read. Gitea's background work like push processing writes the same rows, so merges, issue closes and workflow runs fail sporadically. - Use READ COMMITTED on MySQL and MariaDB, like PostgreSQL and MSSQL - Update xorm to v1.4.3 Replaces: https://github.com/go-gitea/gitea/pull/39494 Fixes: https://github.com/go-gitea/gitea/issues/39492 --------- Signed-off-by: silverwind --- go.mod | 2 +- go.sum | 4 ++-- models/db/engine_init.go | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1d5fdd73bd0..9c474172478 100644 --- a/go.mod +++ b/go.mod @@ -109,7 +109,7 @@ require ( modernc.org/sqlite v1.59.0 mvdan.cc/xurls/v2 v2.6.0 xorm.io/builder v0.3.13 - xorm.io/xorm v1.4.1 + xorm.io/xorm v1.4.3 ) require ( diff --git a/go.sum b/go.sum index e97f448a4d2..aba0eba9fc6 100644 --- a/go.sum +++ b/go.sum @@ -862,5 +862,5 @@ pgregory.net/rapid v0.4.2 h1:lsi9jhvZTYvzVpeG93WWgimPRmiJQfGFRNTEZh1dtY0= pgregory.net/rapid v0.4.2/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU= xorm.io/builder v0.3.13 h1:a3jmiVVL19psGeXx8GIurTp7p0IIgqeDmwhcR6BAOAo= xorm.io/builder v0.3.13/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE= -xorm.io/xorm v1.4.1 h1:m7QlNd0eBGb31IV4Q/ow0Du83rtdC1CiwlvJZGvYde8= -xorm.io/xorm v1.4.1/go.mod h1:cs0ePc8O4a0jD78cNvD+0VFwhqotTvLQZv372QsDw7Q= +xorm.io/xorm v1.4.3 h1:MwWFWzVr+/6D07qGCDhBAfABcuT0gvqY3XmTy1215BM= +xorm.io/xorm v1.4.3/go.mod h1:cs0ePc8O4a0jD78cNvD+0VFwhqotTvLQZv372QsDw7Q= diff --git a/models/db/engine_init.go b/models/db/engine_init.go index a7ae3488da4..4f46bb33660 100644 --- a/models/db/engine_init.go +++ b/models/db/engine_init.go @@ -5,6 +5,7 @@ package db import ( "context" + "database/sql" "fmt" "gitea.dev/modules/log" @@ -59,6 +60,11 @@ func InitEngine(ctx context.Context) error { xe.SetMaxIdleConns(setting.Database.MaxIdleConns) xe.SetConnMaxLifetime(setting.Database.ConnMaxLifetime) + if setting.Database.Type.IsMySQL() { + // like PostgreSQL and MSSQL, avoids MariaDB snapshot isolation errors + xe.SetDefaultTxOptions(&sql.TxOptions{Isolation: sql.LevelReadCommitted}) + } + if setting.Database.SlowQueryThreshold > 0 { xe.AddHook(&EngineHook{ Threshold: setting.Database.SlowQueryThreshold,