diff options
| author | Joakim Hulthe <joakim.hulthe@mullvad.net> | 2025-05-14 12:59:52 +0200 |
|---|---|---|
| committer | Joakim Hulthe <joakim.hulthe@mullvad.net> | 2025-05-14 12:59:52 +0200 |
| commit | 883dda41693e3f55dbc4fe7bccce424df6898f18 (patch) | |
| tree | 42c68adf91eabb06a414d7fd1ad7aa21150fb550 | |
| parent | c19596a01e7c622d1bb1cae20b635c2ffc153bd8 (diff) | |
| parent | 277bb981bc430daccb86b6ded54765c2faa4d240 (diff) | |
| download | mullvadvpn-883dda41693e3f55dbc4fe7bccce424df6898f18.tar.xz mullvadvpn-883dda41693e3f55dbc4fe7bccce424df6898f18.zip | |
Merge branch 'macos-fix-route-channel-delays'
| -rw-r--r-- | talpid-routing/src/unix/macos/default_routes.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/talpid-routing/src/unix/macos/default_routes.rs b/talpid-routing/src/unix/macos/default_routes.rs index e6a68a508d..27594b5251 100644 --- a/talpid-routing/src/unix/macos/default_routes.rs +++ b/talpid-routing/src/unix/macos/default_routes.rs @@ -69,8 +69,10 @@ impl DefaultRouteMonitor { runtime::Handle::current().block_on(monitor.run()); }); - let route_v4_rx = filter_duplicates(delay_nones(NO_ROUTE_GRACE_TIME, route_v4_rx)); - let route_v6_rx = filter_duplicates(delay_nones(NO_ROUTE_GRACE_TIME, route_v6_rx)); + let route_v4_rx = + filter_duplicates(delay_nones_except_first(NO_ROUTE_GRACE_TIME, route_v4_rx)); + let route_v6_rx = + filter_duplicates(delay_nones_except_first(NO_ROUTE_GRACE_TIME, route_v6_rx)); (route_v4_rx, route_v6_rx) } @@ -227,13 +229,13 @@ fn filter_duplicates<T: PartialEq + Clone + Send + 'static>( filtered_rx } -/// Delay `None`-events by `grace_time`. +/// Delay `None`-events by `grace_time`, except for the first value received. /// /// When receiving a `None` on the channel, a timer will start. If no `Some`s are received within /// the deadline, a `None` will be sent. /// /// Some `None`s may be dropped, but `Some`-values are passed along immediately. -fn delay_nones<T: Send + 'static>( +fn delay_nones_except_first<T: Send + 'static>( grace_time: Duration, mut fast_rx: UnboundedReceiver<Option<T>>, ) -> UnboundedReceiver<Option<T>> { @@ -242,6 +244,14 @@ fn delay_nones<T: Send + 'static>( tokio::task::spawn(async move { let mut no_route_grace_timeout = None; + // We send the initial value without any delay + let Some(route) = fast_rx.next().await else { + return; + }; + if slow_tx.unbounded_send(route).is_err() { + return; + } + loop { let no_route_grace_timer = async { match no_route_grace_timeout { |
