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)?;
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue