Skip to content

feat(resolution): resolve destinations off the actor, under one deadline - #197

Merged
dweekly merged 7 commits into
mainfrom
feat/0.19-resolution-off-actor
Nov 27, 2026
Merged

dweekly merged 7 commits into
mainfrom
feat/0.19-resolution-off-actor

Conversation

@dweekly

@dweekly dweekly commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Turning a destination name into an address (getaddrinfo) can stall for tens of seconds when DNS is broken, which is the normal condition for software that diagnoses networks. Until now SwiftFTR made that call on the tracer actor (traces) or on a Swift concurrency thread (ping and the TCP and UDP probes). A stalled lookup therefore froze every other call on the tracer, cancelActiveTraces() and networkChanged() included, could not be cancelled, and had no time limit (finding 5 in docs/ROBUSTNESS-TESTING.md, #84).

This PR moves the call onto the library's blocking-I/O executor, through one small primitive that STUN server-name lookups now share. The wait ends at a deadline, and cancellation releases the caller at once. The address that gets probed does not change. Numeric destinations never queue behind stalled name lookups: either they are answered without a lookup, or they use a one-slot executor of their own (the "Literal Lane"). A ping to 1.1.1.1 while DNS is broken is this library's core diagnostic case.

This is PR 1 of the Resolution Off The Actor slice (docs/BLOCKING-IO.md). PR 2 adds decision 7's configurable budget and makes discoverPaths resolve once.

Invariants

  1. Off the actor. getaddrinfo, and the test seam standing in for it, runs only in a BlockingIOExecutor slot, never on a SwiftFTR actor or a cooperative-pool thread. The seam replaces only that blocking branch.

  2. One deadline. The caller's wait for resolution ends by an absolute deadline on DiscoveryClock. Nothing is submitted once it has passed. An outcome, value or error, that reaches the waiting side after the deadline is a timeout. When several apply, cancellation wins over expiry, and expiry over the lookup's own outcome. Not promised: a lookup may be enqueued in the instant before expiry; it is then withdrawn, or skipped by the worker's own check.

  3. Release. Cancellation by the task or the trace handle, observed during resolution, releases the caller at once with the right error. Each operation checks its task and handle once at the handoff to probing, before it creates a socket.

  4. Same answer. A resolution accepted before its deadline gives what getaddrinfo (or the forced-family parse) gives today. One inline classifier answers, with no seam and no submission:

    • NULs, forced-family literals and family mismatches;
    • .auto IPv4 loopback literals, which Libinfo never synthesizes for;
    • .auto unscoped IPv6 literals outside fe80::/10, fec0::/10 and ff00::/8.

    A test checks byte for byte that these match getaddrinfo. Scoped and embedded-scope forms still go to the resolver.

Caller-visible changes

  • Timeouts. A trace, classified trace, stream or ping whose lookup outlives 20 s throws resolutionFailed(details: "timed out"). Before, it waited for as long as getaddrinfo took.
  • Probes spend one budget. tcpProbe and udpProbe wait for resolution at most timeout from entry and give the probe what is left. If resolution uses it all, they return their existing resolution failure with no socket set up.
  • Cancellation. Cancelling during resolution returns at once, and so do cancelActiveTraces() and networkChanged(). Before, the tracer's calls waited behind the lookup, and a trace cancelled during it still made its socket and sent its probe burst.
  • Ping error precedence. A ping cancelled during its lookup throws CancellationError even when the lookup then fails. Before, it threw resolutionFailed.
  • Shared slots. Names share the eight executor slots with STUN server names. With every slot held, a further name queues until its deadline, and a classified trace can finish without a public address.
  • Late STUN endpoints. A STUN endpoint resolved after its own lookup limit is now discarded.

Reproduce

swift format lint --strict -r Sources Tests
SKIP_NETWORK_TESTS=1 PTR_SKIP_STUN=1 swift test -c debug
SKIP_NETWORK_TESTS=1 PTR_SKIP_STUN=1 swift test -c release
SKIP_NETWORK_TESTS=1 PTR_SKIP_STUN=1 swift test -c debug --filter ResolutionOffActorTests
LIBDISPATCH_COOPERATIVE_POOL_STRICT=1 SKIP_NETWORK_TESTS=1 PTR_SKIP_STUN=1 swift test -c debug --filter ResolutionOffActorTests
swift package diagnose-api-breaking-changes v0.18.1 --products SwiftFTR --breakage-allowlist-path "$PWD/api-breakage-allowlist.txt"

The tests in ResolutionOffActorTests fail on main, except the stream case cancelled by its own consumer, whose behaviour does not change. Run on main, the stall tests hit their 20 s watchdog, and the pool test waits out its 60 s gate.

🤖 Generated with Claude Code

https://claude.ai/code/session_01A8mvWou2vH56zDnkZkqT2X

dweekly and others added 7 commits November 27, 2026 14:53
Forward resolution of trace, traceClassified, traceStream, ping, the TCP and
UDP probes and multipath flows now runs in an executor slot through one
primitive, awaitBlockingLookup, which STUN server-name lookups share. The
caller's wait ends at an absolute deadline on DiscoveryClock (20 s for traces
and ping, config.timeout from entry for the probes); cancellation, by the
task or the trace handle, releases the caller at once, and a trace checks its
handle at the handoff to probing. One inline classifier answers forced-family
literals, mismatches, NULs, IPv4 loopback and unscoped non-link-local IPv6
literals without a resolver or seam; other literals use a one-slot Literal
Lane so stalled name lookups cannot hold back a numeric destination.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A8mvWou2vH56zDnkZkqT2X
Changelog bullet and upgrade-guide entry for each changed caller-visible
behaviour, finding 5 marked fixed with its tests, the API reference's
PreferredFamily notes, and a ROADMAP line for an absolute cutoff in the TCP
and UDP probe operations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A8mvWou2vH56zDnkZkqT2X
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A8mvWou2vH56zDnkZkqT2X
On CI more than half a second passed between entry and the handoff, so the
budget test's probe found nothing left. It now leaves 5 s, still well inside
the 20 s watchdog that a probe given its whole 60 s timeout exceeds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A8mvWou2vH56zDnkZkqT2X
The system resolver treats "127.1" as numeric, but inet_pton does not, so
it was queued with names and waited out the budget when the name slots were
stalled. Lane selection now also accepts what inet_aton recognizes;
resolution itself is unchanged.

The full-executor test pings 127.1; without the change it is still running
at the 20 s watchdog.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A8mvWou2vH56zDnkZkqT2X
inet_aton stops at whitespace and accepts what came before it, so
"127.1 example.com" would have been sent to the lane reserved for numeric
destinations. Lane selection now requires every character to be one a
numeric IPv4 form can contain before asking inet_aton.

numericDestinations fails for the three whitespace cases without the check.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A8mvWou2vH56zDnkZkqT2X
@dweekly
dweekly merged commit 6ff8785 into main Nov 27, 2026
8 checks passed
@dweekly
dweekly deleted the feat/0.19-resolution-off-actor branch November 27, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant