fix: prevent stalled tunnel connections from exhausting threads

This commit is contained in:
Stephen 2026-08-27 09:18:18 -04:00
parent b3e3096b63
commit b916fe51cc
4 changed files with 32 additions and 3 deletions

View file

@ -188,7 +188,9 @@ final class JITEnableContext {
tunnelLock.unlock()
if let waitSemaphore {
waitSemaphore.wait()
guard waitSemaphore.wait(timeout: .now() + .seconds(15)) == .success else {
throw makeError("Timed out waiting for the tunnel connection", code: -19)
}
waitSemaphore.signal()
}

View file

@ -13,11 +13,29 @@ final class MountingProgress: ObservableObject {
@Published private(set) var mountingThread: Thread?
@Published private(set) var coolisMounted: Bool = false
private let mountCheckLock = NSLock()
private var mountCheckInProgress = false
private init() {}
func checkforMounted() {
guard TunnelManager.shared.isConnected else { return }
mountCheckLock.lock()
guard !mountCheckInProgress else {
mountCheckLock.unlock()
return
}
mountCheckInProgress = true
mountCheckLock.unlock()
DispatchQueue.global(qos: .utility).async {
let mounted = isMounted()
self.mountCheckLock.lock()
self.mountCheckInProgress = false
self.mountCheckLock.unlock()
DispatchQueue.main.async {
self.coolisMounted = mounted
}
@ -32,6 +50,8 @@ final class MountingProgress: ObservableObject {
}
func pubMount() {
guard TunnelManager.shared.isConnected else { return }
DispatchQueue.global(qos: .utility).async { [weak self] in
self?.mount()
}

View file

@ -20,10 +20,15 @@ final class InstalledAppsViewModel: ObservableObject {
private let cacheKeyDebuggable = "cachedDebuggableApps"
private let cacheKeyNonDebuggable = "cachedNonDebuggableApps"
private let cacheKeySystem = "cachedSystemApps"
private var cancellables: Set<AnyCancellable> = []
init() {
loadCachedApps()
refreshAppLists()
TunnelManager.shared.$isConnected
.removeDuplicates()
.filter { $0 }
.sink { [weak self] _ in self?.refreshAppLists() }
.store(in: &cancellables)
}
func refreshAppLists() {

View file

@ -83,7 +83,9 @@ struct InstalledAppsListView: View {
handleLoadingChange(isLoading)
}
.onReceive(NotificationCenter.default.publisher(for: .pairingFileImported)) { _ in
viewModel.refreshAppLists()
if TunnelManager.shared.isConnected {
viewModel.refreshAppLists()
}
}
}