Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
Shut down abruptly to work around macOS bug
Browse files Browse the repository at this point in the history
Fixes #111
  • Loading branch information
keeshux committed Jul 7, 2019
1 parent b04f7f2 commit 1dcf4d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider {
guard let session = session else {
flushLog()
completionHandler()
forceExitOnMac()
return
}

Expand All @@ -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)
Expand Down Expand Up @@ -333,7 +335,7 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider {
flushLog()

// failed to start
if (pendingStartHandler != nil) {
if pendingStartHandler != nil {

//
// CAUTION
Expand All @@ -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()
}
}

Expand Down Expand Up @@ -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
}
}

0 comments on commit 1dcf4d7

Please sign in to comment.