Shut down abruptly to work around macOS bug

Fixes #111
This commit is contained in:
Davide De Rosa 2019-07-07 23:34:45 +02:00
parent b04f7f20d4
commit 1dcf4d7745
2 changed files with 20 additions and 2 deletions

View File

@ -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

View File

@ -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
}
}