From 791eabe9bd94d3c97040078e7f577d5db6b6c67f Mon Sep 17 00:00:00 2001 From: spinline Date: Sun, 8 Feb 2026 16:20:55 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20SQLite=20deadlock=20ve=20busy=5Ftimeout?= =?UTF-8?q?=20y=C3=B6netimi=20iyile=C5=9Ftirildi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/db.rs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/backend/src/db.rs b/backend/src/db.rs index 5190363..541cab6 100644 --- a/backend/src/db.rs +++ b/backend/src/db.rs @@ -1,6 +1,7 @@ -use sqlx::{sqlite::SqlitePoolOptions, Pool, Sqlite, Row}; +use sqlx::{sqlite::SqlitePoolOptions, Pool, Sqlite, Row, sqlite::SqliteConnectOptions}; use std::time::Duration; use anyhow::Result; +use std::str::FromStr; #[derive(Clone)] pub struct Db { @@ -9,10 +10,16 @@ pub struct Db { impl Db { pub async fn new(db_url: &str) -> Result { + let options = SqliteConnectOptions::from_str(db_url)? + .create_if_missing(true) + .busy_timeout(Duration::from_secs(10)) // Bekleme süresini 10 saniyeye çıkardık + .journal_mode(sqlx::sqlite::SqliteJournalMode::Wal) + .synchronous(sqlx::sqlite::SqliteSynchronous::Normal); + let pool = SqlitePoolOptions::new() .max_connections(5) - .acquire_timeout(Duration::from_secs(3)) - .connect(db_url) + .acquire_timeout(Duration::from_secs(10)) + .connect_with(options) .await?; let db = Self { pool }; @@ -21,21 +28,6 @@ impl Db { } async fn run_migrations(&self) -> Result<()> { - // WAL mode - enables concurrent reads while writing - sqlx::query("PRAGMA journal_mode=WAL") - .execute(&self.pool) - .await?; - - // NORMAL synchronous - faster than FULL, still safe enough - sqlx::query("PRAGMA synchronous=NORMAL") - .execute(&self.pool) - .await?; - - // 5 second busy timeout - reduces "database locked" errors - sqlx::query("PRAGMA busy_timeout=5000") - .execute(&self.pool) - .await?; - sqlx::migrate!("./migrations").run(&self.pool).await?; Ok(()) }