From e6dad960cf77a3a0fae92ee216d31c9dae59b0ec Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Wed, 23 Nov 2022 20:07:42 -0600 Subject: [PATCH] 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. --- helix-lsp/src/transport.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs index 68b3d15e6..3e3e06eec 100644 --- a/helix-lsp/src/transport.rs +++ b/helix-lsp/src/transport.rs @@ -251,6 +251,16 @@ impl Transport { }; } Err(Error::StreamClosed) => { + // Close any outstanding requests. + for (id, tx) in transport.pending_requests.lock().await.drain() { + match tx.send(Err(Error::StreamClosed)).await { + Ok(_) => (), + Err(_) => { + error!("Could not close request on a closed channel (id={:?})", id) + } + } + } + // Hack: inject a terminated notification so we trigger code that needs to happen after exit use lsp_types::notification::Notification as _; let notification =