Skip to content

Commit

Permalink
Fix bug where block_on was called from an async context
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Jan 7, 2025
1 parent 6d216bc commit c66d8c2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions talpid-wireguard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,13 @@ impl WireguardMonitor {
// timing out on Windows for 2024.9-beta1. These verbose data usage logs are
// a temporary measure to help us understand the issue. They can be removed
// if the issue is resolved.
log_tunnel_data_usage(&config, &tunnel).await;
if let Err(err) =
tokio::task::spawn_blocking(move || log_tunnel_data_usage(&config, &tunnel))
.await
{
log::error!("Failed to log tunnel data during setup phase");
log::error!("{err}");
}
return Err(e);
}

Expand Down Expand Up @@ -989,8 +995,12 @@ impl WireguardMonitor {
}
}

async fn log_tunnel_data_usage(config: &Config, tunnel: &Arc<AsyncMutex<Option<TunnelType>>>) {
let tunnel = tunnel.lock().await;
/// Log the tunnel stats from the current tunnel.
///
/// This will log the amount of outgoing and incoming data to and from the exit (and entry) relay
/// so far.
fn log_tunnel_data_usage(config: &Config, tunnel: &Arc<AsyncMutex<Option<TunnelType>>>) {
let tunnel = tunnel.blocking_lock();
let Some(tunnel) = &*tunnel else { return };
let Ok(tunnel_stats) = tunnel.get_tunnel_stats() else {
return;
Expand Down

0 comments on commit c66d8c2

Please sign in to comment.