diff --git a/tty-fwd/src/api_server.rs b/tty-fwd/src/api_server.rs index d7165285..77e61675 100644 --- a/tty-fwd/src/api_server.rs +++ b/tty-fwd/src/api_server.rs @@ -1014,7 +1014,7 @@ fn handle_session_kill(control_path: &Path, path: &str) -> Response { // Update session status to exited if not already let session_path = control_path.join(&session_id); let session_json_path = session_path.join("session.json"); - + if let Ok(content) = std::fs::read_to_string(&session_json_path) { if let Ok(mut session_info) = serde_json::from_str::(&content) { if session_info.get("status").and_then(|s| s.as_str()) != Some("exited") { @@ -1025,7 +1025,7 @@ fn handle_session_kill(control_path: &Path, path: &str) -> Response { } } } - + let response = ApiResponse { success: Some(true), message: Some("Session killed".to_string()), @@ -1041,7 +1041,7 @@ fn handle_session_kill(control_path: &Path, path: &str) -> Response { // Update session status to exited after killing the process let session_path = control_path.join(&session_id); let session_json_path = session_path.join("session.json"); - + if let Ok(content) = std::fs::read_to_string(&session_json_path) { if let Ok(mut session_info) = serde_json::from_str::(&content) { session_info["status"] = serde_json::json!("exited"); @@ -1051,9 +1051,9 @@ fn handle_session_kill(control_path: &Path, path: &str) -> Response { } } } - + (StatusCode::OK, "Session killed") - }, + } Err(e) => { let response = ApiResponse { success: None, diff --git a/tty-fwd/src/protocol.rs b/tty-fwd/src/protocol.rs index 354dec30..ea4ff7d2 100644 --- a/tty-fwd/src/protocol.rs +++ b/tty-fwd/src/protocol.rs @@ -597,17 +597,19 @@ impl Iterator for StreamingIterator { if self.wait_start.is_none() { self.wait_start = Some(SystemTime::now()); } - + // Check if we've been waiting too long (5 seconds timeout) if let Some(wait_start) = self.wait_start { - if wait_start.elapsed().unwrap_or_default() > std::time::Duration::from_secs(5) { + if wait_start.elapsed().unwrap_or_default() + > std::time::Duration::from_secs(5) + { self.state = StreamingState::Error( - "Timeout waiting for stream file to be created".to_string() + "Timeout waiting for stream file to be created".to_string(), ); return None; } } - + // File doesn't exist yet, wait 50ms and return None to retry later std::thread::sleep(std::time::Duration::from_millis(50)); return None; diff --git a/tty-fwd/src/term_socket.rs b/tty-fwd/src/term_socket.rs index cff2ece2..bc25ddae 100644 --- a/tty-fwd/src/term_socket.rs +++ b/tty-fwd/src/term_socket.rs @@ -404,12 +404,12 @@ fn handle_pty_session( } 0 => { eprintln!("PTY closed (EOF), updating session status"); - + // Send exit event to stream before updating session status let exit_event = json!(["exit", 0, session_id]); writeln!(writer, "{exit_event}")?; writer.flush()?; - + // Update session status to exited let session_json_path = format!("{session_dir}/session.json"); if let Ok(content) = std::fs::read_to_string(&session_json_path) { diff --git a/tty-fwd/src/tty_spawn.rs b/tty-fwd/src/tty_spawn.rs index 9f8540f0..d31e7b33 100644 --- a/tty-fwd/src/tty_spawn.rs +++ b/tty-fwd/src/tty_spawn.rs @@ -449,7 +449,8 @@ fn spawn(mut opts: SpawnOptions) -> Result { // Send exit event to stream before updating session status if let Some(ref mut stream_writer) = stream_writer { - let session_id = opts.session_json_path + let session_id = opts + .session_json_path .as_ref() .and_then(|p| p.file_stem()) .and_then(|s| s.to_str())