Repository navigation
Add privacy-safe mobile dial diagnostics #8264
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c931aea
Add ordered mobile dial diagnostics
azooz2003-bit 327f978
Make terminal resync replay race deterministic
azooz2003-bit 4a50a3c
fix: reconcile diagnostics with authenticated Iroh routing
x90skysn3k 051310a
fix: exclude cancelled dials from failure diagnostics
x90skysn3k baa62fd
test(mobile-rpc): cover cancelled closed connect diagnostics
x90skysn3k 8fb97e2
fix(mobile-rpc): suppress cancelled connect failures
x90skysn3k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileRPCTransportConnectEvent.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import Foundation | ||
|
|
||
| /// A lifecycle event for one underlying mobile transport connection attempt. | ||
| public enum MobileRPCTransportConnectEvent: Sendable { | ||
| /// The transport factory is about to build and dial its route. | ||
| case attempt | ||
| /// The underlying byte transport connected successfully. | ||
| /// - Parameter elapsedMilliseconds: Whole milliseconds since the attempt began. | ||
| case connected(elapsedMilliseconds: Int) | ||
| /// The transport factory or underlying byte transport failed. | ||
| /// - Parameters: | ||
| /// - error: The transport construction or connection error. | ||
| /// - elapsedMilliseconds: Whole milliseconds since the attempt began. | ||
| case failed(error: any Error, elapsedMilliseconds: Int) | ||
| } |
119 changes: 119 additions & 0 deletions
119
...CmuxMobileRPC/Tests/CmuxMobileRPCTests/FirstConnectClosedErrorThenSucceedsTransport.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import CMUXMobileCore | ||
| import Foundation | ||
| @testable import CmuxMobileRPC | ||
|
|
||
| actor FirstConnectClosedErrorThenSucceedsTransport: CmxByteTransport { | ||
| private struct SyntheticClosedError: Error {} | ||
|
|
||
| private var sentPayloads: [Data] = [] | ||
| private var receiveWaiters: [CheckedContinuation<Data?, Never>] = [] | ||
| private var queuedResponses: [Data] = [] | ||
| private var firstConnectRelease: CheckedContinuation<Void, Never>? | ||
| private var firstConnectStartedWaiters: [CheckedContinuation<Void, Never>] = [] | ||
| private var firstConnectFinishedWaiters: [CheckedContinuation<Void, Never>] = [] | ||
| private var firstConnectStarted = false | ||
| private var firstConnectFinished = false | ||
| private var connects = 0 | ||
| private var isClosed = false | ||
|
|
||
| func connect() async throws { | ||
| connects += 1 | ||
| if connects == 1 { | ||
| firstConnectStarted = true | ||
| let startedWaiters = firstConnectStartedWaiters | ||
| firstConnectStartedWaiters = [] | ||
| for waiter in startedWaiters { | ||
| waiter.resume() | ||
| } | ||
| await withCheckedContinuation { continuation in | ||
| firstConnectRelease = continuation | ||
| } | ||
| firstConnectFinished = true | ||
| let finishedWaiters = firstConnectFinishedWaiters | ||
| firstConnectFinishedWaiters = [] | ||
| for waiter in finishedWaiters { | ||
| waiter.resume() | ||
| } | ||
| throw SyntheticClosedError() | ||
| } | ||
| isClosed = false | ||
| } | ||
|
|
||
| func receive() async throws -> Data? { | ||
| if isClosed { | ||
| return nil | ||
| } | ||
| if !queuedResponses.isEmpty { | ||
| return queuedResponses.removeFirst() | ||
| } | ||
| return await withCheckedContinuation { continuation in | ||
| receiveWaiters.append(continuation) | ||
| } | ||
| } | ||
|
|
||
| func send(_ data: Data) async throws { | ||
| var buffer = data | ||
| let payloads = try MobileSyncFrameCodec.decodeFrames(from: &buffer) | ||
| sentPayloads.append(contentsOf: payloads) | ||
| for payload in payloads { | ||
| let request = try recordedRPCRequest(from: payload) | ||
| try enqueueResponse(id: request.id) | ||
| } | ||
| } | ||
|
|
||
| func close() async { | ||
| isClosed = true | ||
| if connects == 1 { | ||
| firstConnectRelease?.resume() | ||
| firstConnectRelease = nil | ||
| return | ||
| } | ||
| let waiters = receiveWaiters | ||
| receiveWaiters = [] | ||
| for waiter in waiters { | ||
| waiter.resume(returning: nil) | ||
| } | ||
| } | ||
|
|
||
| func waitUntilFirstConnectStarted() async { | ||
| if firstConnectStarted { | ||
| return | ||
| } | ||
| await withCheckedContinuation { continuation in | ||
| firstConnectStartedWaiters.append(continuation) | ||
| } | ||
| } | ||
|
|
||
| func waitUntilFirstConnectFinished() async { | ||
| if firstConnectFinished { | ||
| return | ||
| } | ||
| await withCheckedContinuation { continuation in | ||
| firstConnectFinishedWaiters.append(continuation) | ||
| } | ||
| } | ||
|
|
||
| func connectCount() -> Int { | ||
| connects | ||
| } | ||
|
|
||
| func sentRequests() throws -> [RecordedRPCRequest] { | ||
| try sentPayloads.map(recordedRPCRequest(from:)) | ||
| } | ||
|
|
||
| private func enqueueResponse(id: String?) throws { | ||
| let response: [String: Any] = [ | ||
| "id": id ?? "", | ||
| "ok": true, | ||
| "result": ["status": "ok"], | ||
| ] | ||
| let payload = try JSONSerialization.data(withJSONObject: response) | ||
| let frame = try MobileSyncFrameCodec.encodeFrame(payload) | ||
| if let waiter = receiveWaiters.first { | ||
| receiveWaiters.removeFirst() | ||
| waiter.resume(returning: frame) | ||
| } else { | ||
| queuedResponses.append(frame) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
tearDowncancels the in-flight connection task,Task.checkCancellation()orcandidate.connect()throwsCancellationError, which falls into thecatchblock and callstransportConnectObserver?(.failed(error: CancellationError, ...)). At the consumer side,mobileDialFailureKindhas noCancellationErrorbranch, so every intentional cancellation is logged asfailure_kind=transport_error:CancellationError. This inflates observed transport-failure counts in the dial log whenever the user navigates away or a session tears down mid-connect. The fix is to rethrow without calling the observer when the error is a cancellation, so.attemptwithout a corresponding.connectedor.failedimplicitly signals that the attempt was abandoned.