Skip to content

fix(orchestrator): make NNS Recovery on Failover Nodes retry-safe - #11768

Merged
pierugo-dfinity merged 9 commits into
masterfrom
pierugo/upgrade-loop/failover-nns-recovery-retry-safe
Oct 7, 2026
Merged

pierugo-dfinity merged 9 commits into
masterfrom
pierugo/upgrade-loop/failover-nns-recovery-retry-safe

Conversation

@pierugo-dfinity

@pierugo-dfinity pierugo-dfinity commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

During an NNS Recovery on Failover Nodes, the failover nodes' orchestrators detect it by consistently looking for a cup_contents.registry_store_uri in their subnet's CatchUpPackageContents at the latest registry version and download a recovery local store before restarting the orchestrator process. If the download fails, the upgrade loop retries at the next iteration.

Problem

Since the recovery CUP was persisted before attempting the download, the next iteration of the loop now tries to determine its subnet_id out of the recovery CUP, but the latter's registry version corresponds to the new registry, that we haven't extracted yet. The upgrade loop is then stuck inside fn get_subnet_id because it doesn't have the CUP's registry version available.

This download almost always fails the first time in sr_nns_failover_nodes_test because the UVM isn't fully ready yet by the time the nodes attempt to download.

Then why did it not flake before?

The system test setup is not 100% realistic as the original registry has 1 version and the parent NNS registry has 2 versions. The recovery CUP has registry version 2, which by chance (or non-chance), is still valid even when adding the parent NNS mutations on top of the original registry. By modifying the system test and adding a few dummy versions to the original registry (see changes), which is much more realistic, the test starts failing.

Then why did it not appear in the mainnet NNS setup?

The mainnet NNS setup also uses NNS recovery on failover nodes, and with an original registry with many more versions than the parent NNS, so why does it work there?
We were lucky: in this setup, the UVM is already setup before attempting this whole process, so the download never fails and we never stay stuck in a loop.

Why did it appear only now?

#11238 recently made the upgrade loop read the subnet_id between the CUP is persisted but before attempting to download the local store. This is the exact same fn get_subnet_id that returns an error in the scenario described above.

Proposed solution

Make a failed download retry-safe. To do so, we propose to not persist a CUP when it actually corresponds "to a different registry". This means we should look for the registry_store_uri before determining the latest CUP (which persists it). Though this is not sufficient: when restarting the orchestrator process, we want to have persisted the recovery CUP (such that the new process sees it). Thus, persist it precisely just before restarting the process. If the download failed, the CUP wouldn't get persisted and we retry the download in the next iteration.

P.S.: also stop leaking tempdirs if anything fails
P.S. 2: also remove the name on the restored IC to collect IC node logs of the latter (see how sync_with_vector only reads the unnamed IC)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

CUP persistence still precedes an interruptible registry-store replacement, which can recreate the stuck recovery state.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Makes NNS failover recovery retry-safe by delaying recovery CUP persistence until registry download succeeds.

Changes:

  • Checks for NNS recovery before selecting and persisting the latest CUP.
  • Persists the recovery CUP after downloading registry data.
  • Strengthens the failover system-test scenario and enables restored-node log collection.
File Description
rs/​orchestrator/​src/​upgrade.rs Reorders registry recovery and CUP persistence.
rs/​orchestrator/​src/​catch_up_package_provider.rs Exposes CUP persistence within the crate.
rs/​tests/​consensus/​subnet_recovery/​sr_nns_failover_nodes_test.rs Adds realistic registry-version divergence.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread rs/orchestrator/src/upgrade.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The recovery path can overwrite a newer local CUP with a lower registry recovery CUP.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (3)

Comment thread rs/orchestrator/src/upgrade.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The revised ordering addresses failed-download retries consistently, and the accompanying system-test changes exercise realistic registry versions.

Review effort: Balanced
Findings: 1 High severity

Open (1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Post-split destination recovery can still persist its recovery CUP before downloading the replacement registry.

Review effort: Balanced
Findings: 2 High severity

Open (2)

Comment thread rs/orchestrator/src/upgrade.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Failed retries leak persistent temporary directories and may eventually exhaust disk space.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (2)

Comment thread rs/orchestrator/src/upgrade.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

It changes persistence and restart ordering in the critical NNS recovery path, warranting final human validation.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@pierugo-dfinity
pierugo-dfinity marked this pull request as ready for review October 6, 2026 15:49
@pierugo-dfinity
pierugo-dfinity requested a review from a team as a code owner October 6, 2026 15:49
@zeropath-ai

zeropath-ai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to 71cd2a0.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/orchestrator/src/catch_up_package_provider.rs
    persist_cup visibility increased to pub(crate) and parameter formatting changed
Enhancement ► rs/orchestrator/src/upgrade.rs
    import path for protobuf types updated to include pb alias and types::v1 as pb
    introduce registry cup download and persistence flow during upgrade failover handling
    rename function download_registry_and_restart_if_nns_subnet_recovery to download_registry_and_restart_if_nns_failover_nodes_recovery and adjust usage
    add persistence of registry CUP via cup_provider after download
    adjust local store creation to use path() on temp dir and pass to LocalStoreImpl
Enhancement ► rs/tests/consensus/subnet_recovery/sr_nns_failover_nodes_test.rs
    increase test coverage to bump registry version multiple times before failover restore flow; adjust topology snapshot usage accordingly

AleDema pushed a commit to AleDema/ic that referenced this pull request Oct 6, 2026
Hello, me again :D

We need to disable mainnet NNS recovery *again*, this time because it
actually found a real (small) bug in the orchestrator. dfinity#11768 patches
it, meaning we need to wait until it lands in mainnet before being able
to reenable the test.

On top of that
- Remove `--config=flaky_retry` since the test itself takes 2 hours so
let's try it only once.
- Bump `timeout-minutes` by a bit to make Bazel handle the timeout (see
its own `--test_timeout`) and exit more "cleanly".
Comment thread rs/orchestrator/src/upgrade.rs Resolved
Comment thread rs/orchestrator/src/upgrade.rs Resolved
Comment thread rs/orchestrator/src/upgrade.rs Resolved
@pierugo-dfinity
pierugo-dfinity added this pull request to the merge queue Oct 7, 2026
Merged via the queue into master with commit 1a9202b Oct 7, 2026
38 checks passed
@pierugo-dfinity
pierugo-dfinity deleted the pierugo/upgrade-loop/failover-nns-recovery-retry-safe branch October 7, 2026 14:51
AleDema pushed a commit to AleDema/ic that referenced this pull request Oct 11, 2026
…es_test_local (dfinity#11795)

## Problem

`//rs/tests/consensus/subnet_recovery:sr_nns_failover_nodes_test_local`
flaked twice in the week up to 2026-10-08 (2 of 78 runs, both on
master). Both times it failed the same way in the `ProposeCUP` step: all
three of `ic-admin`'s connection attempts to the parent NNS node's
`:8080` timed out (`Failed to connect to [...]:8080: Elapsed(())`, then
`None of the provided NNS urls are reachable`). In the passing retries
the step took 2-4 s.

## Root cause

The Local backend creates each group's bridge with `ip link add name
{bridge} type bridge`, without specifying a MAC address. It creates each
VM's TAP with `ip tuntap add`, which gives the TAP a random MAC. A Linux
bridge whose MAC was not set explicitly takes the lowest MAC among its
ports, and recomputes it whenever a port is added or removed
(`br_stp_recalculate_bridge_id`). The bridge's MAC is the MAC of the
gateway `<prefix>1`, through which GuestOS reaches the driver's
addresses.

Right before `ProposeCUP`, the test starts the `httpbin` universal VM
that serves the registry tarball. Its TAP is the 10th on the bridge, so
in about 1 of 10 runs it has the lowest MAC and the gateway's MAC
changes under the running guests:
- Their neighbour-cache entries for the gateway keep the old MAC, which
still belongs to another TAP.
- So the bridge passes their frames up as `PACKET_OTHERHOST`, and IPv6
input drops them. The one exception is the guest behind the TAP that
owns the old MAC, whose frames still match.
- A guest only recovers once its own entry for the gateway expires and
is re-resolved. The entry stays REACHABLE for a random 15-45 s, then
goes STALE. The next packets go through 5 s of DELAY and 3 unicast
probes before a multicast solicitation finds the new MAC. The host's
neighbour solicitations come from the bridge's link-local address, so
they don't refresh the entry for `<prefix>1`.
- New connections therefore get through again about 23-53 s after the
flip. Long-lived TCP streams resume only at their next retransmission,
after about 53 s or about 107 s.

`ic-admin` gives up 40 s after its first connection attempt. So the test
fails when the parent NNS node is cut off and its random reachable time
is long.

Both failed attempts show this fingerprint. The driver streams the
journald of the restored IC's 5 nodes. In each failure, within about 0.3
s of the httpbin TAP being attached, 4 of those 5 streams stopped. Five
of these eight streams resumed together, 52.6-52.9 s after the attach.
The other three were still silent when the test ended, including the
second failure's parent NNS node. Meanwhile the serial consoles, the
driver and VM-to-VM traffic carried on. The backlog that the first
failure's parent NNS node delivered once its stream resumed shows its
replica finalizing blocks throughout the gap. The passing retries show
no stall.

The MAC flip is as old as the Local backend; what changed is how long
the outage lasts.
- We have logs for 162 passing attempts of this test and its `_head_nns`
variant from before dfinity#11768. In 21 of them (13%), `ProposeCUP` took 11-40
s instead of 2-4 s.
- These durations mostly match `ic-admin` connecting on a later try: it
tries at 0, 15 and 30 s, for up to 10 s each. Seven attempts got through
only on the third and last try, and two of those (39 s and 40 s) only
seconds before it would have given up.
- In those 21 attempts, the parent NNS node's last traffic with the
driver before the flip was the `DownloadParentNNSStore` rsync. It had
ended 15-37 s earlier, so the parent's gateway entry had less REACHABLE
time left when the MAC changed.

dfinity#11768 dropped the name of the restored IC, so the driver now streams
its nodes' journald. That stream keeps the parent's gateway entry fresh
until the very moment of the flip. Of the 40 attempts that ran with this
change, 4 show the fingerprint of a MAC flip. In 3 of those the parent
NNS node was cut off, and 2 of the 3 failed. dfinity#11778, merged 8 minutes
before dfinity#11768, also added guest traffic to `<prefix>1` by serving NTS
there, and CI can't tell the two changes apart.

## Fix

Give the bridge a fixed, deterministic MAC at creation (`ip link add
name {bridge} address {mac} type bridge`). This sets `addr_assign_type`
to `NET_ADDR_SET`, after which the kernel never recomputes the MAC.

The MAC is `6a:ff:` followed by the first 4 bytes of the digest that
also names the bridge. It can't equal a VM's MAC. VM MACs have a
`NodeType` index as their second byte, both in the backend (`vm_mac`:
`6a:01:…`) and in IC-OS (`calculate_deterministic_mac`: `6a:<index>:…`
or `7a:<index>:…`), and 0xff is not a `NodeType` index.

This also covers VM restarts and reboots: `start_vm` deletes and
recreates the VM's TAP, so a restart could move the gateway MAC too.

## Verification

- **Kernel source and namespace reproductions.** I checked the kernel
source (v6.8 and master) and reproduced the bug in unprivileged network
namespaces on the devenv's kernel 6.8.
- The largest reproduction used a bridge set up like `create_group`,
with 9 veth "guests" streaming TCP to an off-link address on `lo`.
- In 4 of 4 runs, attaching a TAP with the lowest MAC cut 8 of the 9
guests off from the host, for about 53 s or about 107 s. VM-to-VM
traffic was unaffected.
- With a fixed bridge MAC, the MAC never changed and no guest lost
connectivity.
- **A/B runs of the real test on the devenv.** These used throwaway
instrumentation, not part of this PR. It gives the httpbin TAP a MAC
lower than any random TAP MAC (`02:00:00:00:00:01`) and logs the
bridge's MAC around every TAP attach.
- **Without the fix**, attaching httpbin's TAP moved the bridge MAC in 2
of 2 runs (e.g. `0e:3d:07:9f:24:f2` → `02:00:00:00:00:01`). In both runs
the journald streams of 4 of the 5 streamed VMs stopped for 53-55 s. The
one survivor was each time the VM whose TAP held the old bridge MAC.
- In the first run, the parent NNS node was among the stalled VMs, and
`ProposeCUP` took 32 s because 2 of `ic-admin`'s 3 tries failed.
- In the second run, the parent NNS node was the survivor, and
`ProposeCUP` took 3.6 s.
- **With the fix**, the bridge kept its `6a:ff:…` MAC through every TAP
attach, including httpbin's `02:00:00:00:00:01`, in 2 of 2 runs. No
journald stream stalled (largest gap 5.5 s), and `ProposeCUP` took 3.6 s
and 2.1 s.
- The runs were sequential. On the 64-core devenv, 3 concurrent runs of
this test (27 VMs with 6 vCPUs each) slowed the VMs so much that the NNS
canister installation timed out (300 s) in setup.
- **This PR as is.** `bazel test --runs_per_test=3 --local_test_jobs=1
//rs/tests/consensus/subnet_recovery:sr_nns_failover_nodes_test_local`
passed 3 of 3, with `ProposeCUP` taking 2.1-4.8 s.
- `//rs/tests/driver:unit_tests` and `//rs/tests/idx:test_e2e_scenarios`
pass, and `ci/scripts/rust-lint.sh` is clean.

This PR was created following the steps in
`.claude/skills/fix-flaky-tests/SKILL.md`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
maksym-arutyunyan pushed a commit to maksym-arutyunyan/ic that referenced this pull request Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants