buildSQLiteDSN augments a SQLite file path with connection pragmas that make the auth DB resilient on slow or contended storage. - _busy_timeout=5000 makes SQLite retry for up to 5s on SQLITE_BUSY instead of failing immediately. Network-backed storage (SMB/CIFS/NFS, e.g. Azure Files) is prone to tr
(path string)
| 28 | // |
| 29 | // Caller-supplied values for either pragma are preserved. |
| 30 | func buildSQLiteDSN(path string) string { |
| 31 | base := path |
| 32 | rawQuery := "" |
| 33 | if i := strings.IndexByte(path, '?'); i >= 0 { |
| 34 | base = path[:i] |
| 35 | rawQuery = path[i+1:] |
| 36 | } |
| 37 | |
| 38 | values, err := url.ParseQuery(rawQuery) |
| 39 | if err != nil { |
| 40 | // An unparseable query string means a hand-crafted DSN we should not |
| 41 | // risk corrupting; leave it untouched. |
| 42 | return path |
| 43 | } |
| 44 | |
| 45 | if values.Get("_busy_timeout") == "" { |
| 46 | values.Set("_busy_timeout", "5000") |
| 47 | } |
| 48 | if values.Get("_txlock") == "" { |
| 49 | values.Set("_txlock", "immediate") |
| 50 | } |
| 51 | |
| 52 | return base + "?" + values.Encode() |
| 53 | } |
no test coverage detected