on master help sign in
Drain pending requests on language server termination (#4852)

This prevents a freeze while shutting down when using `efm-langserver`. `efm-langserver` exits immediately after seeing a shutdown request, without responding to the request. We block awaiting the reply to the shutdown request which will never come, so we time out. This change responds to any pending requests with `Err` saying that the stream has been closed.

commite6dad960cf77a3a0fae92ee216d31c9dae59b0ec authorMichael Davis <mcarsondavis@gmail.com> dateWed 23 Nov 2022, 20:07 (4 years ago) parent1d21683
1 file changed+10
helix-lsp/src/transport.rs+10
helix-lsp/src/transport.rs+10
@@ -251,6 +251,16 @@ impl Transport {
251251 };
252252 }
253253 Err(Error::StreamClosed) => {
254+ // Close any outstanding requests.
255+ for (id, tx) in transport.pending_requests.lock().await.drain() {
256+ match tx.send(Err(Error::StreamClosed)).await {
257+ Ok(_) => (),
258+ Err(_) => {
259+ error!("Could not close request on a closed channel (id={:?})", id)
260+ }
261+ }
262+ }
263+
254264 // Hack: inject a terminated notification so we trigger code that needs to happen after exit
255265 use lsp_types::notification::Notification as _;
256266 let notification =