Repository navigation
fix(lan): the stable port survives the restart handover — a lost race no longer demotes a node to an address nobody has (#1301) - #1369
Merged
Conversation
… no longer demotes a node to an address nobody has (#1301) `stable_lan_port` was correct. Its unit test asserted "same identity must derive the same port across restarts" and passed. The node churned its port on every restart anyway, because of how the bind site handled failure: Err(_preferred_taken) => adapter.listen((UNSPECIFIED, 0)).await Measured on the Windows node 2026-08-15, immediately after `airc update`: peer_id e85a5bb3-74f0-4325-87df-7d5f27637063 -> stable port 61539 daemon advertising -> 64463 61539 at that moment -> BINDABLE. Free, nothing listening, not in any Windows excluded range. The new daemon raced the outgoing one during the update handover, lost by milliseconds, took an ephemeral port, and then held it for the entire process lifetime — after the stable port freed. Every endpoint peers had cached for this node pointed at a dead port. M5 observed the other half independently and without knowing the cause: "your airc INBOUND is unreachable, that is the whole 'everyone waiting on everyone' mystery." Three defects in that one expression: 1. NO RETRY. The contended moment IS the restart handover — the single most common moment this code runs. One attempt loses it. 2. SILENT. `_preferred_taken` discards the reason, so a node that has just become unreachable at every address its peers know reports nothing. That is the masking fallback this repo denies at the clippy gate, written longhand. 3. NO RECOVERY. Once ephemeral, ephemeral for the whole process. Now: retry the identity port briefly (5 x 200ms — bounded, because a genuinely occupied port must surface fast rather than stall startup), and if it still cannot be had, take an ephemeral one but WARN loudly naming the consequence. "Reachable at an address nobody has" is precisely the failure that reads as a quiet room rather than a broken wire, so it must never again be silent. The regression test reproduces the handover: hold the stable port, release it mid-window, assert the bind still lands on the stable port. Positive control run rather than assumed — with the retry reduced to one attempt (the old behaviour) it FAILS on an ephemeral port (64596 vs 64185); restored, it passes. This is the mechanism behind "routes decay to zero after every update", which is what made "always run the latest binary" and "stay connected" fight each other on this node. Verified: cargo test -p airc-lib --lib lan:: — 8 passed, 0 failed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
joelteply
added a commit
that referenced
this pull request
Sep 4, 2026
…he by-hand dial, encoded (#1301 caller side) Measured live 2026-08-15, BigMama -> M5: the peer was enrolled, its Mac answered mDNS, its daemon was LISTENING on its identity-derived stable port — and every STORED endpoint for it carried a stale ephemeral port from the pre-#1369 churn. Discovery dialed corpses and reported "0 routes, 96 enrolled peers". The connection that finally worked was a human doing the derivation by hand: arp/mDNS -> the IP (192.168.1.249) stable_lan_port(id) -> the port (57958, from peer 2f0aed7f) airc dial --expected-peer ... -> CONNECTED, authenticated A user without a terminal cannot do any of that. Joel: "There is no one to manually do shit... all of this must work automatically for users." So the sequence becomes a dial rung. `identity_port_candidates` pairs every IP already known for a peer (stored endpoints; learned IPs ride in via the existing #9 rung) with the ONE port knowable WITHOUT any advertisement: stable_lan_port of the peer's transport host. Derived from the dial PIN, not the record peer — the listener binds the wire-owning scope's identity, so a record answered by a declared host must derive from that host (machine-vs-scope, same rule as the TLS pin). Appended LAST, not prepended: post-#1369 the advertised port IS the stable port, so stored endpoints normally win and this rung costs nothing. It pays exactly when the stored set is stale — churn-era records, or a peer whose bind fell back — and failure-counted eviction retires the corpses so the rung stops paying their timeouts. When a stored endpoint already carries the derived port, no candidate is added (pinned by test). With #1369 (bind keeps the stable port across restarts) this closes the loop from both ends: the listener stays where identity says it should be, and the dialer can now find it there with nothing but the trust store. Verified: cargo test -p airc-lib --lib — 336 passed, 0 failed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
joelteply
added a commit
that referenced
this pull request
Sep 4, 2026
… candidate CI caught what my local run did not: five assertions in stored_endpoint_dial pin exact `peer_dial_failures` / `peer_dial_skips` counts, and the identity-port rung appends one candidate per peer, so each count went 1 -> 2 (and N_TARPITS -> 2 * N_TARPITS). These are CORRECT failures, not noise — the counts are the contract, and they changed. Each site now says why: post-#1369 a peer advertises its stable port, so the derived candidate dedups away and costs nothing; these fixtures use synthetic/churn-era endpoints, which is exactly the case the rung exists for, so they pay one extra fast local dial. The concurrency bound in `peers_are_dialed_concurrently_not_serially` is untouched and still load-bearing: the slow dial per peer is the single 3s tarpit; the derived dial is an instant local refuse adding milliseconds to each peer's serial walk, well inside the 9s ceiling. It passed at 20.4s wall for the whole suite. Verified: cargo test -p airc-lib --test stored_endpoint_dial — 13 passed, 0 failed (was 12/1). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
joelteply
added a commit
that referenced
this pull request
Sep 4, 2026
…he by-hand dial, encoded (#1301 caller side) (#1370) * feat(discovery): the daemon derives a peer's identity port itself — the by-hand dial, encoded (#1301 caller side) Measured live 2026-08-15, BigMama -> M5: the peer was enrolled, its Mac answered mDNS, its daemon was LISTENING on its identity-derived stable port — and every STORED endpoint for it carried a stale ephemeral port from the pre-#1369 churn. Discovery dialed corpses and reported "0 routes, 96 enrolled peers". The connection that finally worked was a human doing the derivation by hand: arp/mDNS -> the IP (192.168.1.249) stable_lan_port(id) -> the port (57958, from peer 2f0aed7f) airc dial --expected-peer ... -> CONNECTED, authenticated A user without a terminal cannot do any of that. Joel: "There is no one to manually do shit... all of this must work automatically for users." So the sequence becomes a dial rung. `identity_port_candidates` pairs every IP already known for a peer (stored endpoints; learned IPs ride in via the existing #9 rung) with the ONE port knowable WITHOUT any advertisement: stable_lan_port of the peer's transport host. Derived from the dial PIN, not the record peer — the listener binds the wire-owning scope's identity, so a record answered by a declared host must derive from that host (machine-vs-scope, same rule as the TLS pin). Appended LAST, not prepended: post-#1369 the advertised port IS the stable port, so stored endpoints normally win and this rung costs nothing. It pays exactly when the stored set is stale — churn-era records, or a peer whose bind fell back — and failure-counted eviction retires the corpses so the rung stops paying their timeouts. When a stored endpoint already carries the derived port, no candidate is added (pinned by test). With #1369 (bind keeps the stable port across restarts) this closes the loop from both ends: the listener stays where identity says it should be, and the dialer can now find it there with nothing but the trust store. Verified: cargo test -p airc-lib --lib — 336 passed, 0 failed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc * test(discovery): the dial suite expects the identity-derived recovery candidate CI caught what my local run did not: five assertions in stored_endpoint_dial pin exact `peer_dial_failures` / `peer_dial_skips` counts, and the identity-port rung appends one candidate per peer, so each count went 1 -> 2 (and N_TARPITS -> 2 * N_TARPITS). These are CORRECT failures, not noise — the counts are the contract, and they changed. Each site now says why: post-#1369 a peer advertises its stable port, so the derived candidate dedups away and costs nothing; these fixtures use synthetic/churn-era endpoints, which is exactly the case the rung exists for, so they pay one extra fast local dial. The concurrency bound in `peers_are_dialed_concurrently_not_serially` is untouched and still load-bearing: the slow dial per peer is the single 3s tarpit; the derived dial is an instant local refuse adding milliseconds to each peer's serial walk, well inside the 9s ceiling. It passed at 20.4s wall for the whole suite. Verified: cargo test -p airc-lib --test stored_endpoint_dial — 13 passed, 0 failed (was 12/1). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.
The measurement
stable_lan_portwas correct. Its unit test asserted "same identity must derive the same port across restarts" and passed. The node churned its port on every restart anyway — because of how the bind site handled failure:Measured on the Windows node today, immediately after
airc update:The new daemon raced the outgoing one during the handover, lost by milliseconds, took an ephemeral port, and held it for the entire process lifetime — long after the stable port freed. Every endpoint peers had cached pointed at a dead port.
M5 observed the other half independently, without knowing the cause: "your airc INBOUND is unreachable, that is the whole 'everyone waiting on everyone' mystery."
Three defects in one expression
_preferred_takendiscards the reason, so a node that has just become unreachable at every address its peers know reports nothing. That's the masking fallback this repo denies at the clippy gate, written longhand.The fix
Retry the identity port briefly — 5 × 200ms, bounded, because a genuinely occupied port must surface fast rather than stall startup. If it still can't be had, take an ephemeral one but warn loudly and name the consequence. "Reachable at an address nobody has" is exactly the failure that reads as a quiet room rather than a broken wire, so it must never be silent again.
Positive control, run rather than assumed
The test holds the stable port, releases it mid-window, and asserts the bind still lands on the stable port. With the retry reduced to one attempt (the old behaviour) it fails on an ephemeral port — 64596 vs 64185. Restored, it passes. So the test catches the regression rather than merely passing alongside the fix.
cargo test -p airc-lib --lib lan::— 8 passed, 0 failed.Why it mattered beyond one node
This is the mechanism behind "routes decay to zero after every update" — which made "always run the latest binary" and "stay connected" actively fight each other. Every update took the node dark at an address no peer could reach, and nothing said so.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc