Skip to content

Commit 87aea87

Browse files
authored
SQLite: when connecting to an in-memory database, limit to 1 concurrent connection (dapr#3255)
Signed-off-by: ItalyPaleAle <[email protected]>
1 parent 8dfa4b6 commit 87aea87

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

state/sqlite/sqlite_dbaccess.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,15 @@ func (a *sqliteDBAccess) Init(ctx context.Context, md state.Metadata) error {
8484
return err
8585
}
8686

87-
db, err := sql.Open("sqlite", connString)
87+
a.db, err = sql.Open("sqlite", connString)
8888
if err != nil {
8989
return fmt.Errorf("failed to create connection: %w", err)
9090
}
9191

92-
a.db = db
92+
// If the database is in-memory, we can't have more than 1 open connection
93+
if a.metadata.IsInMemoryDB() {
94+
a.db.SetMaxOpenConns(1)
95+
}
9396

9497
err = a.Ping(ctx)
9598
if err != nil {

0 commit comments

Comments
 (0)