diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2023-03-01 15:24:17 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2023-03-03 12:01:30 +0100 |
| commit | b17e032c45e6ec4577b8a8e143b9d82715ccfd90 (patch) | |
| tree | ac4563389a13f7767da2867419ebdca221e43bb6 | |
| parent | faece927955044c84bee84208c5cd95ddc22944c (diff) | |
| download | mullvadvpn-b17e032c45e6ec4577b8a8e143b9d82715ccfd90.tar.xz mullvadvpn-b17e032c45e6ec4577b8a8e143b9d82715ccfd90.zip | |
PacketTunnel: ignore all requests to reconnect after the first call to stopTunnel()
| -rw-r--r-- | ios/PacketTunnel/PacketTunnelProvider.swift | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/ios/PacketTunnel/PacketTunnelProvider.swift b/ios/PacketTunnel/PacketTunnelProvider.swift index 3228f1b44e..4a7e10e471 100644 --- a/ios/PacketTunnel/PacketTunnelProvider.swift +++ b/ios/PacketTunnel/PacketTunnelProvider.swift @@ -38,6 +38,10 @@ class PacketTunnelProvider: NEPacketTunnelProvider, TunnelMonitorDelegate { /// completion handler passed into `startTunnel`. private var isConnected = false + /// Raised once tunnel receives the first call to `stopTunnel()`. + /// Once this happens all requests to reconnect the tunnel will be ignored. + private var isStopping = false + /// Flag indicating whether network is reachable. private var isNetworkReachable = true @@ -256,6 +260,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider, TunnelMonitorDelegate { providerLogger.debug("Stop the tunnel: \(reason)") dispatchQueue.async { + self.isStopping = true self.cancelTunnelStartupFailureRecovery() self.startTunnelCompletionHandler = nil } @@ -508,6 +513,9 @@ class PacketTunnelProvider: NEPacketTunnelProvider, TunnelMonitorDelegate { ) { dispatchPrecondition(condition: .onQueue(dispatchQueue)) + // Ignore all requests to reconnect once tunnel is preparing to stop. + guard !isStopping else { return } + let blockOperation = AsyncBlockOperation(dispatchQueue: dispatchQueue) { operation in if shouldStopTunnelMonitor { self.tunnelMonitor.stop() |
