Fix database is locked errors

This commit is contained in:
0x1a8510f2 2022-10-20 21:43:50 +01:00
parent 3cc1b09b42
commit c2fb07c2f4
No known key found for this signature in database
GPG key ID: 1C692E355D76775D

View file

@ -5,6 +5,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"regexp" "regexp"
"strings"
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -25,6 +26,17 @@ func Open(dbProperties *config.DatabaseOptions, writer Writer) (*sql.DB, error)
if err != nil { if err != nil {
return nil, fmt.Errorf("ParseFileURI: %w", err) return nil, fmt.Errorf("ParseFileURI: %w", err)
} }
// add query parameters to the dsn
if strings.Contains(dsn, "?") {
dsn += "&"
} else {
dsn += "?"
}
// wait some time before erroring if the db is locked
// https://gitlab.com/cznic/sqlite/-/issues/106#note_1058094993
dsn += "_pragma=busy_timeout%3d10000"
case dbProperties.ConnectionString.IsPostgres(): case dbProperties.ConnectionString.IsPostgres():
driverName = "postgres" driverName = "postgres"
dsn = string(dbProperties.ConnectionString) dsn = string(dbProperties.ConnectionString)