Description
spawn_lsp_servers_background calls tokio::spawn(...) and discards the returned JoinHandle. This has two consequences:
1. Panics are silently swallowed. If LspServer::spawn_batch, register_servers, or any diagnostics pump task panics, the background task is aborted and the error is lost entirely. No log line, no serve_with return error — just silence. The server continues running, tools return ServerInitializing forever (because clear_expected_languages was never reached), and the user has no way to know initialization failed catastrophically.
2. Pump tasks are not awaited on shutdown. serve_with sends the cancel signal and returns immediately without waiting for diagnostics pump tasks to finish draining. On a graceful shutdown this is low-risk (the process exits anyway), but it makes library-mode usage harder to reason about and prevents clean flush of any in-flight notifications.
Expected Behavior
- A panic in the background init task should surface via the
serve_with return value or at minimum be logged at error level.
serve_with should wait for the background task (and its pump sub-tasks) to complete before returning, giving notifications a chance to drain.
Actual Behavior
The JoinHandle returned by tokio::spawn is dropped immediately. Panics are silently discarded and shutdown does not drain in-flight diagnostics notifications.
Suggested Fix
Return the JoinHandle from spawn_lsp_servers_background, store it in serve_with, and after cancel_tx.send(true) await the handle with a reasonable timeout:
let bg_handle = spawn_lsp_servers_background(...);
// ... run MCP server ...
let _ = cancel_tx.send(true);
let _ = tokio::time::timeout(Duration::from_secs(5), bg_handle).await;
Environment
References
Description
spawn_lsp_servers_backgroundcallstokio::spawn(...)and discards the returnedJoinHandle. This has two consequences:1. Panics are silently swallowed. If
LspServer::spawn_batch,register_servers, or any diagnostics pump task panics, the background task is aborted and the error is lost entirely. No log line, noserve_withreturn error — just silence. The server continues running, tools returnServerInitializingforever (becauseclear_expected_languageswas never reached), and the user has no way to know initialization failed catastrophically.2. Pump tasks are not awaited on shutdown.
serve_withsends the cancel signal and returns immediately without waiting for diagnostics pump tasks to finish draining. On a graceful shutdown this is low-risk (the process exits anyway), but it makes library-mode usage harder to reason about and prevents clean flush of any in-flight notifications.Expected Behavior
serve_withreturn value or at minimum be logged aterrorlevel.serve_withshould wait for the background task (and its pump sub-tasks) to complete before returning, giving notifications a chance to drain.Actual Behavior
The
JoinHandlereturned bytokio::spawnis dropped immediately. Panics are silently discarded and shutdown does not drain in-flight diagnostics notifications.Suggested Fix
Return the
JoinHandlefromspawn_lsp_servers_background, store it inserve_with, and aftercancel_tx.send(true)await the handle with a reasonable timeout:Environment
initializeReferences