on master help sign in
lsp: Handle responses being returned after request timed out.
commit004a4f37a7aadf794ca746f7d9eee4043634cfe2 authorBlaž Hrastnik <blaz@mxxn.io> dateMon 22 Feb 2021, 12:42 (6 years ago) parent8b9b02f
2 files changed+19−18
helix-lsp/src/client.rs−5 helix-lsp/src/transport.rs+19−13
helix-lsp/src/client.rs−5
@@ -121,11 +121,6 @@ impl Client {
121121
122122 let response = serde_json::from_value(response)?;
123123
124− // TODO: we should pass request to a sender thread via a channel
125− // so it can't be interleaved
126−
127− // TODO: responses can be out of order, we need to register a single shot response channel
128−
129124 Ok(response)
130125 }
131126
helix-lsp/src/transport.rs+19−13
@@ -175,24 +175,30 @@ impl Transport {
175175 }
176176
177177 async fn recv_response(&mut self, output: jsonrpc::Output) -> anyhow::Result<()> {
178− match output {
178+ let (id, result) = match output {
179179 jsonrpc::Output::Success(jsonrpc::Success { id, result, .. }) => {
180180 info!("<- {}", result);
181−
182− let tx = self
183− .pending_requests
184− .remove(&id)
185− .expect("pending_request with id not found!");
186− tx.send(Ok(result)).await?;
181+ (id, Ok(result))
187182 }
188183 jsonrpc::Output::Failure(jsonrpc::Failure { id, error, .. }) => {
189− let tx = self
190− .pending_requests
191− .remove(&id)
192− .expect("pending_request with id not found!");
193− tx.send(Err(error.into())).await?;
184+ error!("<- {}", error);
185+ (id, Err(error.into()))
194186 }
195− }
187+ };
188+
189+ let tx = self
190+ .pending_requests
191+ .remove(&id)
192+ .expect("pending_request with id not found!");
193+
194+ match tx.send(result).await {
195+ Ok(_) => (),
196+ Err(_) => error!(
197+ "Tried sending response into a closed channel (id={:?}), original request likely timed out",
198+ id
199+ ),
200+ };
201+
196202 Ok(())
197203 }
198204