From 65636802f7752473d4c4ae5373bb6386977d48e2 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Thu, 28 Aug 2025 22:50:16 -0700 Subject: [PATCH] fix: drop Mutexes earlier in MCP server (#2878) --- codex-rs/mcp-client/src/mcp_client.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/codex-rs/mcp-client/src/mcp_client.rs b/codex-rs/mcp-client/src/mcp_client.rs index 60a454d3..505df6bd 100644 --- a/codex-rs/mcp-client/src/mcp_client.rs +++ b/codex-rs/mcp-client/src/mcp_client.rs @@ -362,7 +362,11 @@ impl McpClient { } }; - if let Some(tx) = pending.lock().await.remove(&id) { + let tx_opt = { + let mut guard = pending.lock().await; + guard.remove(&id) + }; + if let Some(tx) = tx_opt { // Ignore send errors – the receiver might have been dropped. let _ = tx.send(JSONRPCMessage::Response(resp)); } else { @@ -380,7 +384,11 @@ impl McpClient { RequestId::String(_) => return, // see comment above }; - if let Some(tx) = pending.lock().await.remove(&id) { + let tx_opt = { + let mut guard = pending.lock().await; + guard.remove(&id) + }; + if let Some(tx) = tx_opt { let _ = tx.send(JSONRPCMessage::Error(err)); } }