Repository navigation
Skip the trust callback with system roots; retry the iOS protocol test on fresh clients - #2
Merged
Merged
Conversation
…tocol case on fresh clients
Run 42427208429 failed "negotiates the expected protocol" on main: its client's first connection went over HTTP/2,
and the case then made 10 more calls on that same pooled connection, which can never move to HTTP/3.
The simulator's network log shows why the race went to TCP. The server answered the QUIC Initial in 4 ms, but the
client's certificate check ("external verify block") took 151 ms, against 3-8 ms for every other connection in the
run. URLSession started TCP 100 ms in, and TCP finished first. The check goes through the app because
URLSessionBridge's delegate implemented the session trust challenge for every session, even in the plugin, where it
only answered performDefaultHandling. CFNetwork then sends every handshake's certificate check (QUIC and TCP alike)
to the delegate queue: the bridge's single serial queue, which also carries every call's callbacks. Only a bridge
with its own trusted roots (the native tests) now implements the challenge, in a TrustingDelegate subclass.
Tests: the protocol case now uses a fresh client per attempt, sharing the helper the HTTP/3-only cases already used
(harnessOverHttp3, now harnessNegotiating). Each attempt is a client's first call, so on iOS reaching HTTP/3 still
shows that http3Origins made it try QUIC first. That covers the strict "first call goes over HTTP/3" case, which is
dropped: a single fallback under CI load is logged, not failed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW
…ate callback URLSessionBridge's delegate no longer implements the authentication challenge at all. URLSession has no other way to add trust anchors (pinning in Info.plist can only narrow the system's trust), so any custom roots mean a callback that every TLS handshake's certificate check waits on, through the bridge's serial queue. The previous commit kept that path for the native XCTests' own CA; this drops it and trustedRoots with it, so the tests exercise the same handshake path the plugin ships. The tests trust the server's CA through the trust store instead: run_integration_tests.sh already adds it to the simulator's keychain before either suite, so the native suite just stops passing SERVER_CA. The macOS swift-core job adds it to the runner's System keychain, and the README's local loop says how, and how to remove it again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW
The delegate wasn't what held the QUIC handshake. The simulator log shows CFNetwork's "auth completion disp=1" (performDefaultHandling) in the same millisecond it asked the delegate; the 151 ms went to the system's own default trust evaluation, during which the app logged nothing at all for 88 ms: a CPU-starved simulator, not the bridge. The same evaluation took 218 ms at app launch. Restore the delegate, trustedRoots and the native tests' SERVER_CA as they are on main, and the swift-core job without the keychain step. What stays from this branch is the test fix: the protocol case tries fresh clients, since a client that connected over HTTP/2 keeps that connection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW
In run 42427208429 one certificate evaluation took 151 ms, against 2-10 ms for the rest of that run and two earlier green runs, and URLSession's TCP attempt won the race. The bridge's delegate answered performDefaultHandling within a millisecond; the rest happened in the system's evaluation, which runs in trustd, outside the recorded processes. With trustd recorded, the next slow evaluation shows what it waited on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW
… roots
The plugin's delegate implemented urlSession(_:didReceive:completionHandler:) even though, with no trusted roots of
its own, it only ever answered performDefaultHandling. Implementing it at all makes CFNetwork ask the delegate before
its own certificate check on every TLS handshake ("Need to invoke to satisfy trust callback"), so each handshake
waits for the bridge's serial queue.
In run 42671165122 (attempt 2), at app launch, that answer came 126 ms after CFNetwork asked, while trustd was idle.
The app's network thread did nothing in between, the server's QUIC reply sat unprocessed, and the first call went
over HTTP/2.
Only a bridge with its own trusted roots (the native XCTests) now implements the challenge, in a TrustingDelegate
subclass; the shipped plugin leaves certificate checks to the network stack. The subclass names the Objective-C
selector explicitly, since URLSession finds optional delegate methods by selector.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW
Run 42680510479 still logs CFNetwork's "Need to invoke to satisfy trust callback" and "auth completion disp=1" with no challenge method on the delegate, so that step is CFNetwork's own and not caused by implementing the method; the 126 ms before it in the previous run wasn't the bridge's queue. In both runs the launch-time first call lost the race because the whole runner was slow then: the client took 66 ms to set up its QUIC connection, and the Go server processed its first QUIC packet 130 ms after it was sent, against 1-5 ms for every later connection. Not implementing the challenge with the system's roots stays, as the simpler setup; the comment no longer claims it fixes the race. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW
The first call after the app launches lost URLSession's QUIC/TCP race in both of the last two runs: the simulator took 66 ms to set up its QUIC connection and the test server, on the same runner, answered its first QUIC packet 130 ms after it was sent. setUpAll now makes one call on a throwaway client first and logs which protocol it got, without checking it, so the cases start on a warm app and server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes the iOS integration failure on main in run 42427208429. The failing test was
negotiates the expected protocol.What failed
The test's client connected over HTTP/2 on its first call. It then made 10 more calls on that same pooled connection, and a pooled HTTP/2 connection never moves to HTTP/3. The retry loop could not recover.
Why first connections sometimes lose to TCP
URLSession races QUIC against TCP for each new connection, and starts TCP about 100 ms in. A QUIC handshake that's slow past that point loses:
The plugin's URLSession delegate isn't the cause. CFNetwork's "Need to invoke to satisfy trust callback" step happens whether or not the delegate implements the trust challenge.
Changes
negotiates the expected protocol: now uses a fresh client per attempt. It reuses the helper the HTTP/3-only cases already used (harnessOverHttp3, renamedharnessNegotiating(protocol)). Each attempt is a client's first call, made before any Alt-Svc response, so on iOS reaching HTTP/3 still shows thathttp3Originsmade the client try QUIC first.the first call to an HTTP/3 origin goes over HTTP/3is covered by the case above. A fallback is now logged withdebugPrint, not failed. README updated to match.setUpAllmakes one call on a throwaway client before the cases, so they start on a warm app and server. It logs which protocol the call got, without checking it.URLSessionBridge: with the system's roots, the delegate no longer implementsurlSession(_:didReceive:completionHandler:); it only ever answeredperformDefaultHandling. Only a bridge with its own trusted roots (the native XCTests) implements it, in aTrustingDelegatesubclass with an explicit@objcselector. This is simpler, not a fix for the race.Verification
All jobs green on 4beab36, including the native XCTests, which trust the test CA only through
TrustingDelegate. CI on the warm-up commit is running.🤖 Generated with Claude Code
https://claude.ai/code/session_01BqmpXW1H7XRFuEgBWW3ppW