Skip to content

Commit

Permalink
Auto merge of #17208 - Wilfred:log_error_from_threads, r=Veykril
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed May 9, 2024
2 parents 7d1b3a6 + d993f9d commit 5bf2f85
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions crates/rust-analyzer/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,15 @@ fn run_server() -> anyhow::Result<()> {
config.rediscover_workspaces();
}

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

io_threads.join()?;
tracing::info!("server did shut down");
Ok(())
}
Expand Down

0 comments on commit 5bf2f85

Please sign in to comment.