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
pull/2451/head^2
Michael Davis 3 years ago committed by GitHub
parent 0258cf45f3
commit 50dd11985c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -215,13 +215,7 @@ impl Transport {
} }
}; };
let tx = self if let Some(tx) = self.pending_requests.lock().await.remove(&id) {
.pending_requests
.lock()
.await
.remove(&id)
.expect("pending_request with id not found!");
match tx.send(result).await { match tx.send(result).await {
Ok(_) => (), Ok(_) => (),
Err(_) => error!( Err(_) => error!(
@ -229,6 +223,13 @@ impl Transport {
id id
), ),
}; };
} else {
log::error!(
"Discarding Language Server response without a request (id={:?}) {:?}",
id,
result
);
}
Ok(()) Ok(())
} }

Loading…
Cancel
Save