lsp: Handle responses being returned after request timed out.

pull/8/head
Blaž Hrastnik 3 years ago
parent 8b9b02f08b
commit 004a4f37a7

@ -121,11 +121,6 @@ impl Client {
let response = serde_json::from_value(response)?; let response = serde_json::from_value(response)?;
// TODO: we should pass request to a sender thread via a channel
// so it can't be interleaved
// TODO: responses can be out of order, we need to register a single shot response channel
Ok(response) Ok(response)
} }

@ -175,24 +175,30 @@ impl Transport {
} }
async fn recv_response(&mut self, output: jsonrpc::Output) -> anyhow::Result<()> { 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, .. }) => { jsonrpc::Output::Success(jsonrpc::Success { id, result, .. }) => {
info!("<- {}", result); info!("<- {}", result);
(id, Ok(result))
let tx = self
.pending_requests
.remove(&id)
.expect("pending_request with id not found!");
tx.send(Ok(result)).await?;
} }
jsonrpc::Output::Failure(jsonrpc::Failure { id, error, .. }) => { jsonrpc::Output::Failure(jsonrpc::Failure { id, error, .. }) => {
let tx = self error!("<- {}", error);
.pending_requests (id, Err(error.into()))
.remove(&id)
.expect("pending_request with id not found!");
tx.send(Err(error.into())).await?;
} }
} };
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(()) Ok(())
} }

Loading…
Cancel
Save