Skip to content

Commit ddb3b9f

Browse files
committed
chore: dont stop vpn on device sleep
1 parent 6417d16 commit ddb3b9f

File tree

2 files changed

+5
-34
lines changed

2 files changed

+5
-34
lines changed

Coder-Desktop/VPN/Manager.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ actor Manager {
3232
let sessionConfig = URLSessionConfiguration.default
3333
// The tunnel might be asked to start before the network interfaces have woken up from sleep
3434
sessionConfig.waitsForConnectivity = true
35-
// URLSession's waiting for connectivity sometimes hangs even when
36-
// the network is up so this is deliberately short (30s) to avoid a
37-
// poor UX where it appears stuck.
38-
sessionConfig.timeoutIntervalForResource = 30
35+
// Timeout after 5 minutes, or if there's no data for 60 seconds
36+
sessionConfig.timeoutIntervalForRequest = 60
37+
sessionConfig.timeoutIntervalForResource = 300
3938
try await download(src: dylibPath, dest: dest, urlSession: URLSession(configuration: sessionConfig))
4039
} catch {
4140
throw .download(error)

Coder-Desktop/VPN/PacketTunnelProvider.swift

+2-30
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
5757
start(completionHandler)
5858
}
5959

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

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

141-
// sleep and wake reference: https://developer.apple.com/forums/thread/95988
142-
override func sleep(completionHandler: @escaping () -> Void) {
143-
logger.debug("sleep called")
144-
teardown(completionHandler)
145-
}
146-
147-
override func wake() {
148-
// It's possible the tunnel is still starting up, if it is, wake should
149-
// be a no-op.
150-
guard !reasserting else { return }
151-
guard manager == nil else {
152-
logger.error("wake called with non-nil Manager")
153-
return
154-
}
155-
logger.debug("wake called")
156-
reasserting = true
157-
currentSettings = .init(tunnelRemoteAddress: "127.0.0.1")
158-
setTunnelNetworkSettings(nil)
159-
start { error in
160-
if let error {
161-
self.logger.error("error starting tunnel after wake: \(error.localizedDescription)")
162-
self.cancelTunnelWithError(error)
163-
} else {
164-
self.reasserting = false
165-
}
166-
}
167-
}
168-
169141
// Wrapper around `setTunnelNetworkSettings` that supports merging updates
170142
func applyTunnelNetworkSettings(_ diff: Vpn_NetworkSettingsRequest) async throws {
171143
logger.debug("applying settings diff: \(diff.debugDescription, privacy: .public)")

0 commit comments

Comments
 (0)