Skip to content

Commit

Permalink
prevent panic when handling an LSP response with no request (helix-ed…
Browse files Browse the repository at this point in the history
…itor#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 helix-editor#2474, the language server sends an error message
with a null request ID which should not ever exist in the
`pending_requests` HashMap.

closes helix-editor#2474
  • Loading branch information
the-mikedavis authored and mtoohey31 committed Jun 15, 2022
1 parent 47cf3c8 commit c9cd301
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions helix-lsp/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit c9cd301

Please sign in to comment.