From 004a4f37a7aadf794ca746f7d9eee4043634cfe2 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Mon, 22 Feb 2021 12:42:56 +0900 Subject: lsp: Handle responses being returned after request timed out. --- helix-lsp/src/transport.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'helix-lsp/src/transport.rs') diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs index a14bc1f7..74ecde5e 100644 --- a/helix-lsp/src/transport.rs +++ b/helix-lsp/src/transport.rs @@ -175,24 +175,30 @@ impl Transport { } async fn recv_response(&mut self, output: jsonrpc::Output) -> anyhow::Result<()> { - match output { + let (id, result) = match output { jsonrpc::Output::Success(jsonrpc::Success { id, result, .. }) => { info!("<- {}", result); - - let tx = self - .pending_requests - .remove(&id) - .expect("pending_request with id not found!"); - tx.send(Ok(result)).await?; + (id, Ok(result)) } jsonrpc::Output::Failure(jsonrpc::Failure { id, error, .. }) => { - let tx = self - .pending_requests - .remove(&id) - .expect("pending_request with id not found!"); - tx.send(Err(error.into())).await?; + error!("<- {}", error); + (id, Err(error.into())) } - } + }; + + let tx = self + .pending_requests + .remove(&id) + .expect("pending_request with id not found!"); + + match tx.send(result).await { + Ok(_) => (), + Err(_) => error!( + "Tried sending response into a closed channel (id={:?}), original request likely timed out", + id + ), + }; + Ok(()) } -- cgit v1.2.3-70-g09d2