diff options
author | Michael Davis | 2022-05-17 05:45:34 +0000 |
---|---|---|
committer | GitHub | 2022-05-17 05:45:34 +0000 |
commit | 50dd11985c107b9ed1abb7ca4ebc95f02deff9cf (patch) | |
tree | 7b027f272a7839ad9d4cafcd5a65e40aaee4fdde | |
parent | 0258cf45f300eb2ac1119be4186a83bfa5835bd9 (diff) |
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
-rw-r--r-- | helix-lsp/src/transport.rs | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs index 6e28094d..6102c6c8 100644 --- a/helix-lsp/src/transport.rs +++ b/helix-lsp/src/transport.rs @@ -215,20 +215,21 @@ impl Transport { } }; - let tx = self - .pending_requests - .lock() - .await - .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 - ), - }; + if let Some(tx) = self.pending_requests.lock().await.remove(&id) { + match tx.send(result).await { + Ok(_) => (), + Err(_) => error!( + "Tried sending response into a closed channel (id={:?}), original request likely timed out", + id + ), + }; + } else { + log::error!( + "Discarding Language Server response without a request (id={:?}) {:?}", + id, + result + ); + } Ok(()) } |