diff --git a/CHANGELOG.md b/CHANGELOG.md index 6999a82..f8ffbcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Tunnel dies unexpectedly on macOS. [#111](https://github.com/passepartoutvpn/tunnelkit/issues/111) + ## 1.7.1 (2019-05-14) ### Added diff --git a/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift b/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift index b106f3d..cf872c7 100644 --- a/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift +++ b/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift @@ -241,6 +241,7 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { guard let session = session else { flushLog() completionHandler() + forceExitOnMac() return } @@ -255,6 +256,7 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { log.warning("Tunnel not responding after \(weakSelf.shutdownTimeout) milliseconds, forcing stop") weakSelf.flushLog() pendingHandler() + self?.forceExitOnMac() } tunnelQueue.sync { session.shutdown(error: nil) @@ -333,7 +335,7 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { flushLog() // failed to start - if (pendingStartHandler != nil) { + if pendingStartHandler != nil { // // CAUTION @@ -355,13 +357,15 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { pendingStartHandler = nil } // stopped intentionally - else if (pendingStopHandler != nil) { + else if pendingStopHandler != nil { pendingStopHandler?() pendingStopHandler = nil + forceExitOnMac() } // stopped externally, unrecoverable else { cancelTunnelWithError(error) + forceExitOnMac() } } @@ -843,3 +847,11 @@ private extension Proxy { return NEProxyServer(address: address, port: Int(port)) } } + +private extension NEPacketTunnelProvider { + func forceExitOnMac() { + #if os(macOS) + exit(0) + #endif + } +}