Skip to content

Commit

Permalink
fix: force sqlite connection singleton to avoid database lock error
Browse files Browse the repository at this point in the history
  • Loading branch information
yezizp2012 committed Feb 2, 2024
1 parent 8fdd0ba commit 099cc0b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/meta/node/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,17 @@ pub async fn rpc_serve(
)
}
MetaStoreBackend::Sql { endpoint } => {
let max_connection = if DbBackend::Sqlite.is_prefix_of(&endpoint) {
// Due to the fact that Sqlite is prone to the error "(code: 5) database is locked" under concurrent access,
// here we forcibly specify the number of connections as 1.
1
} else {
10
};

let mut options = sea_orm::ConnectOptions::new(endpoint);
options
.max_connections(20)
.max_connections(max_connection)
.connect_timeout(Duration::from_secs(10))
.idle_timeout(Duration::from_secs(30));
let conn = sea_orm::Database::connect(options).await?;
Expand Down

0 comments on commit 099cc0b

Please sign in to comment.