Repository navigation
fix(apple): prevent utun increments from IPC calls - #10855
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
open question: shall we allow |
thomaseizinger
left a comment
There was a problem hiding this comment.
Nice work! Some minor, mostly stylistic feedback.
867b14c to
91b8f13
Compare
jamilbk
left a comment
There was a problem hiding this comment.
In the right direction! I think we need to clean up a couple things.
On macOS, IPC calls to the network extension can wake it whilst not connected, causing the system to create a utun device (utun0, utun1, utun2...). If startTunnel() is not subsequently called, these devices persist and accumulate over time. The existing dryStartStopCycle() mechanism was introduced to wake the extension after upgrades, but other IPC operations (log management functions) could also wake the extension without proper cleanup. Solution -------- Add wrapper functions in IPCClient that automatically handle wake-up and cleanup lifecycle for IPC calls made whilst disconnected: - Check VPN connection status - If connected: execute IPC operation directly (utun already exists) - If disconnected: wake extension → wait 500ms → execute IPC → cleanup
91b8f13 to
e31a983
Compare
thomaseizinger
left a comment
There was a problem hiding this comment.
One more non-blocking comment, otherwise LGTM
There was a problem hiding this comment.
@klochowicz I pushed several cleanup changes and a few bug fixes. Please review the most recent commits and let me know if you have any questions.
@thomaseizinger Another review would be much appreciated.
Tested
- Log count / clear / export works on iOS and macOS
-
utundoes not increment in either connected or disconnected states on macOS and iOS - Configuration is persisted and latest is used on macOS / iOS
- Configuration observer does not send IPC calls unless
TunnelConfigurationinstance has meaningfully changed.
|
|
||
| if session.status != .connected { | ||
| Log.trace("Not setting configuration whilst not connected") |
There was a problem hiding this comment.
Our private version of sendProviderMessage handles this case for us now.
| @@ -52,33 +52,10 @@ import System | |||
| .appendingPathComponent("tunnel.zip") | |||
| fileManager.createFile(atPath: tunnelLogURL.path, contents: nil) | |||
| let fileHandle = try FileHandle(forWritingTo: tunnelLogURL) | |||
| defer { try? fileHandle.close() } | |||
There was a problem hiding this comment.
Ensures we close the file handle regardless of outcome.
| // Get data from the provider - if hash matches, provider returns nil | ||
| let data = try await withCheckedThrowingContinuation { | ||
| (continuation: CheckedContinuation<Data?, Error>) in | ||
| do { | ||
| guard session.status == .connected else { | ||
| throw IPCClient.Error.invalidStatus(session.status) | ||
| } | ||
|
|
||
| try session.sendProviderMessage( | ||
| IPCClient.encoder.encode(ProviderMessage.getResourceList(currentHash)) | ||
| ) { data in | ||
| continuation.resume(returning: data) | ||
| } | ||
| } catch { | ||
| continuation.resume(throwing: error) | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
This business logic was moved back into IPCClient, where we can leverage the new sendProviderMessage private func to have consistent IPC call semantics.
Not sure how it escaped, but it would probably be a tad cleaner to keep IPC calls in that module instead of calling them directly from other areas of the codebase.
24d9be4 to
ef9258d
Compare
thomaseizinger
left a comment
There was a problem hiding this comment.
LGTM
I left a suggestion for a more type-safe interface although I am not sure if this can be expressed in Swift.
|
Merging to get into next release |
This reverts commit bdffa3a.
A regression was introduced in #10855 that introduced a `Task {}` closure upon each iteration of the log export loop that was never awaited. This meant that the log export IPC call returned after the first chunk was written, which triggered the `defer` block which stopped the tunnel and caused the next iteration of the task to return `nil` data, corrupting the log archive. To fix this, we ensure the ipc calls happen within the loop, passing control flow logic back to the caller to ultimately determine if further IPC calls to grab logs should be made. No changelog since not released yet.
In #10855, we removed the passing of the configuration through startTunnel based on the assumption that a prior `setConfiguration` call would have occurred in order to hydrate the configuration cache. Unfortunately, on iOS, this is not the case, resulting in a bug on fresh installs of iOS that prevents the tunnel from starting because it has no configuration. Related: https://app.hubspot.com/live-messages/23723443/inbox/10333087281
On macOS, IPC calls to the network extension can wake it whilst not
connected, causing the system to create a utun device.
If startTunnel() is not subsequently called, these devices
persist and accumulate over time.
The existing dryStartStopCycle() mechanism was introduced to wake the
extension after upgrades, but other IPC operations (log management
functions) could also wake the extension without proper cleanup.
Solution
Add wrapper functions in IPCClient that automatically handle wake-up
and cleanup lifecycle for IPC calls made whilst disconnected:
Implementation
For async IPC operations (clearLogs, getLogFolderSize):
Created free functions in IPCClient that wrap low-level IPC calls
with wrapIPCCallIfNeeded():
For callback-based exportLogs:
We cannot use wrapper because exportLogs returns immediately and uses
callbacks for streaming chunks. Wrapper would call stop() before
export finishes, killing the extension mid-stream.
Solution: Manual wake-up/cleanup in LogExporter where we already have
continuation that waits for chunk.done signal:
Fixes #10580