Skip to content

Commit

Permalink
Merge branch 'patch-block-on-in-tokio-task' into prepare-2025.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Jan 7, 2025
2 parents 6d216bc + beee5dc commit d56bff9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Line wrap the file at 100 chars. Th
#### Windows
- Add experimental support for Windows ARM64.

### Fixed
- Fix crash when Wireguard tunnel setup timed out.

## [2025.1] - 2025-01-02
### Fixed
#### macOS
Expand Down
26 changes: 22 additions & 4 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 @@ -484,7 +490,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 +1001,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 Expand Up @@ -1023,6 +1039,8 @@ enum CloseMsg {
pub(crate) trait Tunnel: Send {
fn get_interface_name(&self) -> String;
fn stop(self: Box<Self>) -> std::result::Result<(), TunnelError>;
/// # Note
/// This function should *not* be called from within an async context.
fn get_tunnel_stats(&self) -> std::result::Result<stats::StatsMap, TunnelError>;
fn set_config<'a>(
&'a mut self,
Expand Down

0 comments on commit d56bff9

Please sign in to comment.