[fix](trx-frontend-http): avoid decode history deadlock
Co-authored-by: OpenAI <assistant@openai.com> Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
@@ -148,11 +148,13 @@ pub fn clear_ft8_history() {
|
|||||||
|
|
||||||
/// Set the decode broadcast channel from the client main.
|
/// Set the decode broadcast channel from the client main.
|
||||||
pub fn set_decode_channel(tx: broadcast::Sender<DecodedMessage>) {
|
pub fn set_decode_channel(tx: broadcast::Sender<DecodedMessage>) {
|
||||||
let mut ch = decode_channel()
|
{
|
||||||
.lock()
|
let mut ch = decode_channel()
|
||||||
.expect("decode channel mutex poisoned");
|
.lock()
|
||||||
*ch = Some(tx);
|
.expect("decode channel mutex poisoned");
|
||||||
start_decode_history_collector();
|
*ch = Some(tx.clone());
|
||||||
|
}
|
||||||
|
start_decode_history_collector(tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Subscribe to the decode broadcast channel, if available.
|
/// Subscribe to the decode broadcast channel, if available.
|
||||||
@@ -163,7 +165,7 @@ pub fn subscribe_decode() -> Option<broadcast::Receiver<DecodedMessage>> {
|
|||||||
ch.as_ref().map(|tx| tx.subscribe())
|
ch.as_ref().map(|tx| tx.subscribe())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_decode_history_collector() {
|
fn start_decode_history_collector(tx: broadcast::Sender<DecodedMessage>) {
|
||||||
static STARTED: OnceLock<Mutex<bool>> = OnceLock::new();
|
static STARTED: OnceLock<Mutex<bool>> = OnceLock::new();
|
||||||
let started = STARTED.get_or_init(|| Mutex::new(false));
|
let started = STARTED.get_or_init(|| Mutex::new(false));
|
||||||
let mut started_guard = started.lock().expect("decode history start mutex poisoned");
|
let mut started_guard = started.lock().expect("decode history start mutex poisoned");
|
||||||
@@ -172,13 +174,6 @@ fn start_decode_history_collector() {
|
|||||||
}
|
}
|
||||||
*started_guard = true;
|
*started_guard = true;
|
||||||
|
|
||||||
let ch = decode_channel()
|
|
||||||
.lock()
|
|
||||||
.expect("decode channel mutex poisoned");
|
|
||||||
let Some(tx) = ch.as_ref().cloned() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut rx = tx.subscribe();
|
let mut rx = tx.subscribe();
|
||||||
loop {
|
loop {
|
||||||
|
|||||||
Reference in New Issue
Block a user