From 27b2330b2c65779760d55e866ed0fa6182b2fce4 Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Wed, 26 Jun 2024 18:49:03 +0200 Subject: [PATCH] Avoids handling VPN wake events when disconnected (#860) ## Description We're emoving known noise from wake pixels, and tunnel update pixels, plus potentially removing unnecessary calls to backend and other code handling that shouldn't happen when the VPN is disconnected. --- .../NetworkProtection/PacketTunnelProvider.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Sources/NetworkProtection/PacketTunnelProvider.swift b/Sources/NetworkProtection/PacketTunnelProvider.swift index 886872394..b8fe9ab02 100644 --- a/Sources/NetworkProtection/PacketTunnelProvider.swift +++ b/Sources/NetworkProtection/PacketTunnelProvider.swift @@ -1516,19 +1516,25 @@ open class PacketTunnelProvider: NEPacketTunnelProvider { // MARK: - Computer sleeping + @MainActor public override func sleep() async { os_log("Sleep", log: .networkProtectionSleepLog, type: .info) - await connectionTester.stop() - await tunnelFailureMonitor.stop() - await latencyMonitor.stop() - await entitlementMonitor.stop() - await serverStatusMonitor.stop() + await stopMonitors() } + @MainActor public override func wake() { os_log("Wake up", log: .networkProtectionSleepLog, type: .info) + // macOS can launch the extension due to calls to `sendProviderMessage`, so there's + // a chance this is being called when the VPN isn't really meant to be connected or + // running. We want to avoid firing pixels or handling adapter changes when this is + // the case. + guard connectionStatus != .disconnected else { + return + } + Task { providerEvents.fire(.tunnelWakeAttempt(.begin))