From ac531354d52f67bb29255cc31db3ad8e4e09b7f9 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Mon, 11 Aug 2025 10:44:39 -0300 Subject: [PATCH] fix: prevent duplicate database connection in server mode Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) --- src/modes/server.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/modes/server.rs b/src/modes/server.rs index 4cfe7bc..25417ff 100644 --- a/src/modes/server.rs +++ b/src/modes/server.rs @@ -94,23 +94,21 @@ pub fn mode_server( // We need to move the connection into the async runtime let rt = tokio::runtime::Runtime::new()?; - rt.block_on(run_server(config, conn, data_path, args)) + // Take ownership of the connection and move it into the async runtime + let owned_conn = std::mem::replace(conn, rusqlite::Connection::open_in_memory()?); + rt.block_on(run_server(config, owned_conn, data_path, args)) } async fn run_server( config: ServerConfig, - _conn: &mut rusqlite::Connection, + conn: rusqlite::Connection, data_dir: PathBuf, args: &Args, ) -> Result<()> { debug!("Starting REST HTTP server on {}", config.address); - // Create a new database connection for the server - // Note: This is a simplified approach. In production, you'd want a connection pool - let mut db_path = data_dir.clone(); - db_path.push("keep-1.db"); - let new_conn = crate::db::open(db_path)?; - let db_conn = Arc::new(Mutex::new(new_conn)); + // Use the existing database connection + let db_conn = Arc::new(Mutex::new(conn)); let state = AppState { db: db_conn,