fix: prevent duplicate database connection in server mode

Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-11 10:44:39 -03:00
parent 29aa477417
commit ac531354d5

View File

@@ -94,23 +94,21 @@ pub fn mode_server(
// We need to move the connection into the async runtime // We need to move the connection into the async runtime
let rt = tokio::runtime::Runtime::new()?; 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( async fn run_server(
config: ServerConfig, config: ServerConfig,
_conn: &mut rusqlite::Connection, conn: rusqlite::Connection,
data_dir: PathBuf, data_dir: PathBuf,
args: &Args, args: &Args,
) -> Result<()> { ) -> Result<()> {
debug!("Starting REST HTTP server on {}", config.address); debug!("Starting REST HTTP server on {}", config.address);
// Create a new database connection for the server // Use the existing database connection
// Note: This is a simplified approach. In production, you'd want a connection pool let db_conn = Arc::new(Mutex::new(conn));
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));
let state = AppState { let state = AppState {
db: db_conn, db: db_conn,