Skip to content

Commit 1c78d80

Browse files
committed
SQLite has a query timeout. Fixes 'database locked' errors
1 parent b38b61b commit 1c78d80

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

conf/app.ini

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ PASSWD =
166166
SSL_MODE = disable
167167
; For "sqlite3" and "tidb", use absolute path when you start as service
168168
PATH = data/gitea.db
169+
; For "sqlite3" only. Query timeout
170+
SQLITE_TIMEOUT = 500
169171

170172
[indexer]
171173
ISSUE_INDEXER_PATH = indexers/issues.bleve

models/models.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var (
6666
// DbCfg holds the database settings
6767
DbCfg struct {
6868
Type, Host, Name, User, Passwd, Path, SSLMode string
69+
Timeout int
6970
}
7071

7172
// EnableSQLite3 use SQLite3
@@ -151,6 +152,7 @@ func LoadConfigs() {
151152
}
152153
DbCfg.SSLMode = sec.Key("SSL_MODE").String()
153154
DbCfg.Path = sec.Key("PATH").MustString("data/gitea.db")
155+
DbCfg.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
154156

155157
sec = setting.Cfg.Section("indexer")
156158
setting.Indexer.IssuePath = sec.Key("ISSUE_INDEXER_PATH").MustString("indexers/issues.bleve")
@@ -220,7 +222,7 @@ func getEngine() (*xorm.Engine, error) {
220222
if err := os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm); err != nil {
221223
return nil, fmt.Errorf("Failed to create directories: %v", err)
222224
}
223-
connStr = "file:" + DbCfg.Path + "?cache=shared&mode=rwc"
225+
connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d", DbCfg.Path, DbCfg.Timeout)
224226
case "tidb":
225227
if !EnableTiDB {
226228
return nil, errors.New("this binary version does not build support for TiDB")

0 commit comments

Comments
 (0)