Skip to content

Commit 5bf2f85

Browse files
committed
Auto merge of #17208 - Wilfred:log_error_from_threads, r=Veykril
fix: Report both IO errors and main_loop errors If rust-analyzer receives a malformed LSP request, the IO thread terminates with a meaningful error, but then closes the channel. Once the channel has closed, the main_loop also terminates, but it only has RecvError and can't show a meaningful error. As a result, rust-analyzer would incorrectly claim that the client forgot to shutdown. ``` $ buggy_lsp_client | rust-analyzer Error: client exited without proper shutdown sequence ``` Instead, include both error messages when the server shuts down.
2 parents 7d1b3a6 + d993f9d commit 5bf2f85

File tree

1 file changed

+8
-2
lines changed
  • crates/rust-analyzer/src/bin

1 file changed

+8
-2
lines changed

crates/rust-analyzer/src/bin/main.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,15 @@ fn run_server() -> anyhow::Result<()> {
259259
config.rediscover_workspaces();
260260
}
261261

262-
rust_analyzer::main_loop(config, connection)?;
262+
// If the io_threads have an error, there's usually an error on the main
263+
// loop too because the channels are closed. Ensure we report both errors.
264+
match (rust_analyzer::main_loop(config, connection), io_threads.join()) {
265+
(Err(loop_e), Err(join_e)) => anyhow::bail!("{loop_e}\n{join_e}"),
266+
(Ok(_), Err(join_e)) => anyhow::bail!("{join_e}"),
267+
(Err(loop_e), Ok(_)) => anyhow::bail!("{loop_e}"),
268+
(Ok(_), Ok(_)) => {}
269+
}
263270

264-
io_threads.join()?;
265271
tracing::info!("server did shut down");
266272
Ok(())
267273
}

0 commit comments

Comments
 (0)