Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions cli/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,11 @@ fn connect(session: &str) -> Result<Connection, String> {
}

pub fn send_command(cmd: Value, session: &str) -> Result<Response, String> {
// Retry logic for transient errors (EAGAIN/EWOULDBLOCK/connection issues)
const MAX_RETRIES: u32 = 5;
const RETRY_DELAY_MS: u64 = 200;
// Retry logic for transient errors (EAGAIN/EWOULDBLOCK/connection issues).
// Use generous retries to handle slow or resource-constrained environments
// (e.g. VMs) where the daemon may be slow to start or respond.
const MAX_RETRIES: u32 = 8;
const RETRY_DELAY_MS: u64 = 500;

let mut last_error = String::new();

Expand Down Expand Up @@ -543,6 +545,9 @@ fn send_command_once(cmd: &Value, session: &str) -> Result<Response, String> {
stream
.write_all(json_str.as_bytes())
.map_err(|e| format!("Failed to send: {}", e))?;
stream
.flush()
.map_err(|e| format!("Failed to send: {}", e))?;

let mut reader = BufReader::new(stream);
let mut response_line = String::new();
Expand Down
4 changes: 4 additions & 0 deletions cli/src/native/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ async fn handle_connection<S>(
let mut resp = serde_json::to_string(&err).unwrap_or_default();
resp.push('\n');
let _ = writer.write_all(resp.as_bytes()).await;
let _ = writer.flush().await;
continue;
}
};
Expand All @@ -380,6 +381,9 @@ async fn handle_connection<S>(
if writer.write_all(resp.as_bytes()).await.is_err() {
break;
}
if writer.flush().await.is_err() {
break;
}

if is_close {
if let Some(ref path) = stream_file_cleanup {
Expand Down
Loading