Skip to content

chore: dont stop coder connect on device sleep #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Coder-Desktop/VPN/Manager.swift
Original file line number Diff line number Diff line change
@@ -32,10 +32,9 @@ actor Manager {
let sessionConfig = URLSessionConfiguration.default
// The tunnel might be asked to start before the network interfaces have woken up from sleep
sessionConfig.waitsForConnectivity = true
// URLSession's waiting for connectivity sometimes hangs even when
// the network is up so this is deliberately short (30s) to avoid a
// poor UX where it appears stuck.
sessionConfig.timeoutIntervalForResource = 30
// Timeout after 5 minutes, or if there's no data for 60 seconds
sessionConfig.timeoutIntervalForRequest = 60
sessionConfig.timeoutIntervalForResource = 300
try await download(src: dylibPath, dest: dest, urlSession: URLSession(configuration: sessionConfig))
} catch {
throw .download(error)
32 changes: 2 additions & 30 deletions Coder-Desktop/VPN/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
start(completionHandler)
}

// called by `startTunnel` and on `wake`
// called by `startTunnel`
func start(_ completionHandler: @escaping (Error?) -> Void) {
guard let proto = protocolConfiguration as? NETunnelProviderProtocol,
let baseAccessURL = proto.serverAddress
@@ -108,7 +108,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
teardown(completionHandler)
}

// called by `stopTunnel` and `sleep`
// called by `stopTunnel`
func teardown(_ completionHandler: @escaping () -> Void) {
guard let manager else {
logger.error("teardown called with nil Manager")
@@ -138,34 +138,6 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
}
}

// sleep and wake reference: https://developer.apple.com/forums/thread/95988
override func sleep(completionHandler: @escaping () -> Void) {
logger.debug("sleep called")
teardown(completionHandler)
}

override func wake() {
// It's possible the tunnel is still starting up, if it is, wake should
// be a no-op.
guard !reasserting else { return }
guard manager == nil else {
logger.error("wake called with non-nil Manager")
return
}
logger.debug("wake called")
reasserting = true
currentSettings = .init(tunnelRemoteAddress: "127.0.0.1")
setTunnelNetworkSettings(nil)
start { error in
if let error {
self.logger.error("error starting tunnel after wake: \(error.localizedDescription)")
self.cancelTunnelWithError(error)
} else {
self.reasserting = false
}
}
}

// Wrapper around `setTunnelNetworkSettings` that supports merging updates
func applyTunnelNetworkSettings(_ diff: Vpn_NetworkSettingsRequest) async throws {
logger.debug("applying settings diff: \(diff.debugDescription, privacy: .public)")
PHP-Proxy

PHP-Proxy

Error accessing resource: 404 - Not Found