From 4a2d23981d39be8559757b54f0201adcba5496c3 Mon Sep 17 00:00:00 2001 From: guillep2k <18600385+guillep2k@users.noreply.github.com> Date: Wed, 26 Feb 2020 20:51:37 -0300 Subject: [PATCH] Fix SQLite concurrency problems by using BEGIN IMMEDIATE (#10368) * Test locking immediate for SQLite3 * fix url field separator Co-authored-by: Lunny Xiao Co-authored-by: zeripath --- integrations/migration-test/migration_test.go | 2 +- models/unit_tests.go | 2 +- modules/setting/database.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integrations/migration-test/migration_test.go b/integrations/migration-test/migration_test.go index 6cdfbf7d7..a4d01efef 100644 --- a/integrations/migration-test/migration_test.go +++ b/integrations/migration-test/migration_test.go @@ -126,7 +126,7 @@ func restoreOldDB(t *testing.T, version string) bool { err := os.MkdirAll(path.Dir(setting.Database.Path), os.ModePerm) assert.NoError(t, err) - db, err := sql.Open("sqlite3", fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d", setting.Database.Path, setting.Database.Timeout)) + db, err := sql.Open("sqlite3", fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate", setting.Database.Path, setting.Database.Timeout)) assert.NoError(t, err) defer db.Close() diff --git a/models/unit_tests.go b/models/unit_tests.go index b9f894af7..b2c487ddc 100644 --- a/models/unit_tests.go +++ b/models/unit_tests.go @@ -88,7 +88,7 @@ func MainTest(m *testing.M, pathToGiteaRoot string) { // CreateTestEngine creates a memory database and loads the fixture data from fixturesDir func CreateTestEngine(fixturesDir string) error { var err error - x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared") + x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared&_txlock=immediate") if err != nil { return err } diff --git a/modules/setting/database.go b/modules/setting/database.go index 911ac90a0..85043e8c1 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -126,7 +126,7 @@ func DBConnStr() (string, error) { if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil { return "", fmt.Errorf("Failed to create directories: %v", err) } - connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d", Database.Path, Database.Timeout) + connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate", Database.Path, Database.Timeout) default: return "", fmt.Errorf("Unknown database type: %s", Database.Type) }