From d577c8a864a7b9939c14a8b07343bd08a71476f0 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Sun, 18 Jan 2026 09:37:08 -0500 Subject: [PATCH] fix(mcp): Gracefully shutdown background indexing task on exit The background indexing task was not being properly terminated when the MCP server shut down, causing a panic in the lance library when task handles were cancelled during tokio runtime shutdown. Signed-off-by: Sasha Levin --- src/bin/semcode-mcp.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bin/semcode-mcp.rs b/src/bin/semcode-mcp.rs index d37b8a7..cf656cf 100644 --- a/src/bin/semcode-mcp.rs +++ b/src/bin/semcode-mcp.rs @@ -5437,7 +5437,7 @@ async fn main() -> Result<()> { let git_repo_for_indexing = args.git_repo.clone(); let indexing_state_for_bg = server.indexing_state.clone(); let notification_tx_for_bg = server.notification_tx.clone(); - let _indexing_handle = tokio::spawn(async move { + let indexing_handle = tokio::spawn(async move { // Ensure tables exist before indexing if let Err(e) = db_for_indexing.create_tables().await { eprintln!("[Background] Error creating/verifying tables: {}", e); @@ -5458,6 +5458,10 @@ async fn main() -> Result<()> { // Run MCP server on stdio run_stdio_server(server).await?; + // Gracefully shutdown the background indexing task + indexing_handle.abort(); + let _ = indexing_handle.await; + Ok(()) }