From f9c0fa69815d37785df9fab11a39fdb9923e77c0 Mon Sep 17 00:00:00 2001 From: Stan Grams Date: Fri, 6 Mar 2026 15:45:10 +0100 Subject: [PATCH] [fix](trx-server): add rig task timeouts to avoid stalls Co-authored-by: OpenAI Codex Signed-off-by: Stan Grams --- src/trx-server/src/rig_task.rs | 37 ++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/trx-server/src/rig_task.rs b/src/trx-server/src/rig_task.rs index debf953..8078713 100644 --- a/src/trx-server/src/rig_task.rs +++ b/src/trx-server/src/rig_task.rs @@ -27,6 +27,9 @@ use trx_core::{DynResult, RigError, RigResult}; use crate::audio::DecoderHistories; use crate::error::is_invalid_bcd_error; +const POLL_REFRESH_TIMEOUT: Duration = Duration::from_secs(8); +const COMMAND_EXEC_TIMEOUT: Duration = Duration::from_secs(10); + /// Configuration for the rig task. pub struct RigTaskConfig { pub registry: Arc, @@ -271,8 +274,13 @@ pub async fn run_rig_task( // Poll rig state let old_state = state.clone(); - match refresh_state_with_retry(&mut rig, &mut state, retry).await { - Ok(()) => { + match time::timeout( + POLL_REFRESH_TIMEOUT, + refresh_state_with_retry(&mut rig, &mut state, retry), + ) + .await + { + Ok(Ok(())) => { let old_machine_state = machine.state().clone(); sync_machine_state(&mut machine, &state); let new_machine_state = machine.state().clone(); @@ -285,7 +293,7 @@ pub async fn run_rig_task( ); let _ = state_tx.send(state.clone()); } - Err(e) => { + Ok(Err(e)) => { error!("CAT polling error: {:?}", e); // Grace period after power on if let Some(last_on) = last_power_on { @@ -295,6 +303,12 @@ pub async fn run_rig_task( } } } + Err(_) => { + error!( + "CAT polling timed out after {:?}", + POLL_REFRESH_TIMEOUT + ); + } } }, @@ -324,7 +338,22 @@ pub async fn run_rig_task( retry, histories: &histories, }; - let result = process_command(cmd, &mut cmd_ctx).await; + let result = + match time::timeout(COMMAND_EXEC_TIMEOUT, process_command(cmd, &mut cmd_ctx)) + .await + { + Ok(result) => result, + Err(_) => { + error!( + "Rig command {} timed out after {:?}", + cmd_label, COMMAND_EXEC_TIMEOUT + ); + Err(RigError::communication(format!( + "command timed out after {:?}", + COMMAND_EXEC_TIMEOUT + ))) + } + }; let _ = respond_to.send(result);