fix(io): replace blocking I/O with async in hot paths

Three subsystems were using std::fs (blocking) inside async context,
which stalls the tokio runtime thread during I/O:

- DashboardMetrics::save(): now uses tokio::fs::write + rename
- TokenStore::flush_last_used(): now uses tokio::fs for batch updates
- AuditLog::log(): moved file write to spawn_blocking (fire-and-forget)

The background task and shutdown handler now properly .await the
async save/flush methods. AuditLog writer wrapped in Arc for
cross-thread access from spawn_blocking.
This commit is contained in:
2026-04-02 12:17:47 +00:00
parent 848f5f5571
commit be7e882391
4 changed files with 38 additions and 30 deletions

View File

@@ -441,9 +441,9 @@ async fn run_server(config: Config, storage: Storage) {
let mut interval = tokio::time::interval(std::time::Duration::from_secs(30));
loop {
interval.tick().await;
metrics_state.metrics.save();
metrics_state.metrics.save().await;
if let Some(ref token_store) = metrics_state.tokens {
token_store.flush_last_used();
token_store.flush_last_used().await;
}
registry::docker::cleanup_expired_sessions(&metrics_state.upload_sessions);
}
@@ -459,7 +459,7 @@ async fn run_server(config: Config, storage: Storage) {
.expect("Server error");
// Save metrics on shutdown
state.metrics.save();
state.metrics.save().await;
info!(
uptime_seconds = state.start_time.elapsed().as_secs(),