on master help sign in
prevent panic when handling an LSP response with no request (#2475)

A language server may push a response which doesn't belong to any request. With this change, we discard the response rather than crashing. In the case of #2474, the language server sends an error message with a null request ID which should not ever exist in the `pending_requests` HashMap. closes #2474

commit50dd11985c107b9ed1abb7ca4ebc95f02deff9cf authorMichael Davis <mcarsondavis@gmail.com> dateTue 17 May 2022, 00:45 (4 years ago) parent0258cf4
1 file changed+15−14
helix-lsp/src/transport.rs+15−14
helix-lsp/src/transport.rs+15−14
@@ -215,20 +215,21 @@ impl Transport {
215215 }
216216 };
217217
218− let tx = self
219− .pending_requests
220− .lock()
221− .await
222− .remove(&id)
223− .expect("pending_request with id not found!");
224−
225− match tx.send(result).await {
226− Ok(_) => (),
227− Err(_) => error!(
228− "Tried sending response into a closed channel (id={:?}), original request likely timed out",
229− id
230− ),
231− };
218+ if let Some(tx) = self.pending_requests.lock().await.remove(&id) {
219+ match tx.send(result).await {
220+ Ok(_) => (),
221+ Err(_) => error!(
222+ "Tried sending response into a closed channel (id={:?}), original request likely timed out",
223+ id
224+ ),
225+ };
226+ } else {
227+ log::error!(
228+ "Discarding Language Server response without a request (id={:?}) {:?}",
229+ id,
230+ result
231+ );
232+ }
232233
233234 Ok(())
234235 }