From b142d68ca29afbe8db4b722ecc3c782c59b4c346 Mon Sep 17 00:00:00 2001 From: Stanislaw Grams Date: Sat, 7 Feb 2026 15:14:31 +0100 Subject: [PATCH] [fix](trx-server): fix busy-loop in rig polling caused by interval recreation time::interval() fires its first tick immediately. Recreating it on every loop iteration made the select! always resolve instantly, turning the main polling loop into a busy-loop (~13% CPU idle). Replace with a Box::pin(sleep()) that is only reset after it completes or when the poll duration changes (rx/tx transition). Co-Authored-By: Claude Opus 4.6 Signed-off-by: Stanislaw Grams --- src/trx-server/src/rig_task.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/trx-server/src/rig_task.rs b/src/trx-server/src/rig_task.rs index f0969e5..f021e7b 100644 --- a/src/trx-server/src/rig_task.rs +++ b/src/trx-server/src/rig_task.rs @@ -211,12 +211,20 @@ pub async fn run_rig_task( let _ = state_tx.send(state.clone()); // Main task loop + let mut current_poll_duration = polling.interval(state.status.tx_en); + let mut poll_sleep: std::pin::Pin> = + Box::pin(tokio::time::sleep(current_poll_duration)); loop { - let poll_duration = polling.interval(state.status.tx_en); - let mut poll_interval = time::interval(poll_duration); + // Update sleep duration if tx_en state changed + let new_duration = polling.interval(state.status.tx_en); + if new_duration != current_poll_duration { + current_poll_duration = new_duration; + poll_sleep = Box::pin(tokio::time::sleep(current_poll_duration)); + } tokio::select! { - _ = poll_interval.tick() => { + _ = &mut poll_sleep => { + poll_sleep = Box::pin(tokio::time::sleep(current_poll_duration)); // Check if polling is paused if let Some(until) = poll_pause_until { if Instant::now() < until {