lsp: Handle responses being returned after request timed out.
This commit is contained in:
parent
8b9b02f08b
commit
004a4f37a7
2 changed files with 19 additions and 18 deletions
|
@ -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))
|
||||||
|
}
|
||||||
|
jsonrpc::Output::Failure(jsonrpc::Failure { id, error, .. }) => {
|
||||||
|
error!("<- {}", error);
|
||||||
|
(id, Err(error.into()))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let tx = self
|
let tx = self
|
||||||
.pending_requests
|
.pending_requests
|
||||||
.remove(&id)
|
.remove(&id)
|
||||||
.expect("pending_request with id not found!");
|
.expect("pending_request with id not found!");
|
||||||
tx.send(Ok(result)).await?;
|
|
||||||
}
|
match tx.send(result).await {
|
||||||
jsonrpc::Output::Failure(jsonrpc::Failure { id, error, .. }) => {
|
Ok(_) => (),
|
||||||
let tx = self
|
Err(_) => error!(
|
||||||
.pending_requests
|
"Tried sending response into a closed channel (id={:?}), original request likely timed out",
|
||||||
.remove(&id)
|
id
|
||||||
.expect("pending_request with id not found!");
|
),
|
||||||
tx.send(Err(error.into())).await?;
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue