Skip to content

Commit 4fd0bc6

Browse files
freeinternet865freeinternet865
andauthored
ui: handle proxy task shutdown more reliably (#25)
Log server.run() errors in the UI background task instead of silently discarding them. Also abort the task if graceful shutdown times out, and make sure a finished or stopped proxy task clears the running flag consistently without wiping the last visible stats snapshot. Co-authored-by: freeinternet865 <free@internet865.com>
1 parent 819bbb7 commit 4fd0bc6

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/bin/ui.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,35 +1573,39 @@ fn background_thread(shared: Arc<Shared>, rx: Receiver<Cmd>) {
15731573
),
15741574
);
15751575

1576-
let _ = server.run(shutdown_rx).await;
1576+
if let Err(e) = server.run(shutdown_rx).await {
1577+
push_log(&shared2, &format!("[ui] proxy error: {}", e));
1578+
}
15771579

15781580
shared2.state.lock().unwrap().running = false;
1581+
shared2.state.lock().unwrap().started_at = None;
15791582
push_log(&shared2, "[ui] proxy stopped");
15801583
});
15811584

15821585
active = Some((handle, fronter_slot, shutdown_tx));
15831586
}
15841587

15851588
Ok(Cmd::Stop) => {
1586-
if let Some((handle, _, shutdown_tx)) = active.take() {
1589+
if let Some((mut handle, _, shutdown_tx)) = active.take() {
15871590
push_log(&shared, "[ui] stop requested");
15881591
let _ = shutdown_tx.send(());
15891592

15901593
// Give the proxy 2 seconds to shut down gracefully
15911594
rt.block_on(async {
15921595
tokio::select! {
1593-
_ = handle => {
1596+
_ = &mut handle => {
15941597
push_log(&shared, "[ui] proxy stopped gracefully");
15951598
}
15961599
_ = tokio::time::sleep(tokio::time::Duration::from_secs(2)) => {
1597-
push_log(&shared, "[ui] shutdown timeout, forcing abort");
1600+
handle.abort();
1601+
let _ = handle.await;
1602+
push_log(&shared, "[ui] shutdown timeout, forced abort");
15981603
}
15991604
}
16001605
});
16011606

16021607
shared.state.lock().unwrap().running = false;
16031608
shared.state.lock().unwrap().started_at = None;
1604-
shared.state.lock().unwrap().last_stats = None;
16051609
}
16061610
}
16071611

@@ -1762,6 +1766,7 @@ fn background_thread(shared: Arc<Shared>, rx: Receiver<Cmd>) {
17621766
if handle.is_finished() {
17631767
active = None;
17641768
shared.state.lock().unwrap().running = false;
1769+
shared.state.lock().unwrap().started_at = None;
17651770
}
17661771
}
17671772
}

0 commit comments

Comments
 (0)