lsp: Handle responses being returned after request timed out.

This commit is contained in:
Blaž Hrastnik 2021-02-22 12:42:56 +09:00
parent 8b9b02f08b
commit 004a4f37a7
2 changed files with 19 additions and 18 deletions

View file

@ -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)
}

View file

@ -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);
(id, Ok(result))
}
jsonrpc::Output::Failure(jsonrpc::Failure { id, error, .. }) => {
error!("<- {}", error);
(id, Err(error.into()))
}
};
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, .. }) => {
let tx = self
.pending_requests
.remove(&id)
.expect("pending_request with id not found!");
tx.send(Err(error.into())).await?;
}
}
match tx.send(result).await {
Ok(_) => (),
Err(_) => error!(
"Tried sending response into a closed channel (id={:?}), original request likely timed out",
id
),
};
Ok(())
}