Skip to content

Commit 098deeb

Browse files
authored
Fix: mcp client background task entering a hot loop on child process crash (#146)
1 parent 0047b27 commit 098deeb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

crates/chat-cli/src/mcp_client/client.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,16 @@ where
363363
},
364364
Err(e) => {
365365
tracing::error!("Background listening thread for client {}: {:?}", server_name, e);
366+
// If we don't have anything on the other end, we should just end the task
367+
// now
368+
if let TransportError::RecvError(tokio::sync::broadcast::error::RecvError::Closed) = e {
369+
tracing::error!(
370+
"All senders dropped for transport layer for server {}: {:?}. This likely means the mcp server process is no longer running.",
371+
server_name,
372+
e
373+
);
374+
break;
375+
}
366376
},
367377
}
368378
}

crates/chat-cli/src/mcp_client/transport/stdio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl JsonRpcStdioTransport {
5151
// Messages are delimited by newlines and assumed to contain no embedded newlines
5252
// See https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/transports/#stdio
5353
match buf_reader.read_until(b'\n', &mut buffer).await {
54-
Ok(0) => continue,
54+
Ok(0) => break,
5555
Ok(_) => match serde_json::from_slice::<JsonRpcMessage>(buffer.as_slice()) {
5656
Ok(msg) => {
5757
let _ = tx.send(Ok(msg));

0 commit comments

Comments
 (0)