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
This commit is contained in:
Michael Davis 2022-05-17 00:45:34 -05:00 committed by GitHub
parent 0258cf45f3
commit 50dd11985c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -215,20 +215,21 @@ async fn process_request_response(&self, output: jsonrpc::Output) -> Result<()>
} }
}; };
let tx = self if let Some(tx) = self.pending_requests.lock().await.remove(&id) {
.pending_requests match tx.send(result).await {
.lock() Ok(_) => (),
.await Err(_) => error!(
.remove(&id) "Tried sending response into a closed channel (id={:?}), original request likely timed out",
.expect("pending_request with id not found!"); id
),
match tx.send(result).await { };
Ok(_) => (), } else {
Err(_) => error!( log::error!(
"Tried sending response into a closed channel (id={:?}), original request likely timed out", "Discarding Language Server response without a request (id={:?}) {:?}",
id id,
), result
}; );
}
Ok(()) Ok(())
} }