Retain self weakly for shutdown on timeout

This commit is contained in:
Davide De Rosa 2019-05-02 13:13:20 +02:00
parent 705be661b0
commit d44d08c95e
1 changed files with 7 additions and 4 deletions

View File

@ -245,12 +245,15 @@ open class TunnelKitProvider: NEPacketTunnelProvider {
}
pendingStopHandler = completionHandler
tunnelQueue.schedule(after: .milliseconds(shutdownTimeout)) {
guard let pendingHandler = self.pendingStopHandler else {
tunnelQueue.schedule(after: .milliseconds(shutdownTimeout)) { [weak self] in
guard let weakSelf = self else {
return
}
log.warning("Tunnel not responding after \(self.shutdownTimeout) milliseconds, forcing stop")
self.flushLog()
guard let pendingHandler = weakSelf.pendingStopHandler else {
return
}
log.warning("Tunnel not responding after \(weakSelf.shutdownTimeout) milliseconds, forcing stop")
weakSelf.flushLog()
pendingHandler()
}
tunnelQueue.sync {