Fix Neovim connection deadlock by dropping NVIM_CONN lock across await boundary

This commit is contained in:
Riz Ashraf committed 2026-09-21 04:04:32 +01:00
1 parent b98f95d9d8
commit 9870626045
2 files changed
+6 -2

No files matched your search

+4 -1
View File
@@ -126,12 +126,14 @@ pub struct NvimRequest {
static NVIM_CONN: LazyLock<Arc<Mutex<Option<mpsc::Sender<NvimRequest>>>>> = LazyLock::new(|| Arc::new(Mutex::new(None))); static NVIM_CONN: LazyLock<Arc<Mutex<Option<mpsc::Sender<NvimRequest>>>>> = LazyLock::new(|| Arc::new(Mutex::new(None)));
async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> { async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
let mut conn_lock = NVIM_CONN.lock().await; {
let conn_lock = NVIM_CONN.lock().await;
if let Some(sender) = conn_lock.as_ref() { if let Some(sender) = conn_lock.as_ref() {
if !sender.is_closed() { if !sender.is_closed() {
return Ok(sender.clone()); return Ok(sender.clone());
} }
} }
}
tracing::info!("Establishing new persistent connection to Neovim"); tracing::info!("Establishing new persistent connection to Neovim");
let socket_path = get_socket_path().await?; let socket_path = get_socket_path().await?;
@@ -228,6 +230,7 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
} }
}); });
let mut conn_lock = NVIM_CONN.lock().await;
*conn_lock = Some(tx.clone()); *conn_lock = Some(tx.clone());
Ok(tx) Ok(tx)
} }
+2 -1
View File
@@ -249,7 +249,8 @@ fn run_server(state: Arc<MemoryState>) -> Result<(), Box<dyn std::error::Error>>
post( post(
|headers: axum::http::HeaderMap, State(state): State<Arc<AppState>>| async move { |headers: axum::http::HeaderMap, State(state): State<Arc<AppState>>| async move {
let token_path = state.handler.state.base_dir.join("admin.token"); let token_path = state.handler.state.base_dir.join("admin.token");
let expected_token = std::fs::read_to_string(&token_path) let expected_token = tokio::fs::read_to_string(&token_path)
.await
.unwrap_or_default() .unwrap_or_default()
.trim() .trim()
.to_string(); .to_string();