fix: drop Mutexes earlier in MCP server (#2878)

This commit is contained in:
Michael Bolin
2025-08-28 22:50:16 -07:00
committed by GitHub
parent c988ce28fe
commit 65636802f7

View File

@@ -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. // Ignore send errors the receiver might have been dropped.
let _ = tx.send(JSONRPCMessage::Response(resp)); let _ = tx.send(JSONRPCMessage::Response(resp));
} else { } else {
@@ -380,7 +384,11 @@ impl McpClient {
RequestId::String(_) => return, // see comment above 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)); let _ = tx.send(JSONRPCMessage::Error(err));
} }
} }