Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where block_on was called from an async context #7425

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading