Skip to content

worker/local: root tests intermittently see a NAT pair as not created yet #1471

Open

Description

@privateip

Part of #1430.

Observed

Two root tests in internal/worker/local fail intermittently in CI's Unit Tests (root) job with the same symptom. A NAT pair's state reads back as Pending, "not created yet", at a step where the test expects it Ready:

Both passed when the job was rerun, both pass repeatedly locally (40 of 40 and 8 of 8 runs), and neither PR changed the code path the failing test exercises.

Expected

The root tests in internal/worker/local pass on every run. If the pair's creation is asynchronous, the tests wait on the condition they assert, or the module reports the pair Ready only once it exists, whichever matches the intended contract.

Acceptance

The fixing PR:

  • identifies whether the race is in the module or in the tests, with a reproduction (for example under -count with CPU or scheduler stress) that fails before the fix;
  • makes both tests pass at least 200 consecutive runs as root under the same stress;
  • doesn't weaken what either test asserts.

Activity

  1. added theissue type on Nov 20, 2026
  2. privateip commented on Nov 21, 2026

    @privateip
    ContributorAuthor

    A third intermittent root-test failure in internal/worker/local, with a different symptom, on #1478 (which doesn't touch this package):

    TestEntryPathsRoot/vlan-generic failed at local_root_test.go:74 with "a second plan would write again". That is the idempotency check, which found work left after a plan had already been applied. A rerun of the job passed. It failed in Actions run 44877885995, job 136766521251, attempt 1.

    This may share a cause with the Pending reads above: state that hasn't settled when the test checks it. Whoever fixes this issue should check this test as well, and cover it in the 200-run stress check.

  3. self-assigned this
    on Nov 21, 2026
  4. privateip commented on Nov 21, 2026

    @privateip
    ContributorAuthor

    Valid, and the race is in the module, not the tests.

    Reproduction (base 1c118386, -race test binary run as root under niced CPU load, 2 or 3 test processes in parallel):

    • The original TestUntrustedEntryRoot and TestHookWithdrawalAndRepairRoot, 3 processes at -count 40, failed once with the CI symptom: the pair read back as Pending, "the service-internal veth pair is not created yet".
    • A throwaway steady-state loop failed in both of 2 processes. It builds a ready rig, then runs 3000 reads and dry-run plans per VPC while nothing changes. 4 reads came back Pending and 4 plans came back dirty. A dirty plan is the TestEntryPathsRoot/vlan-generic symptom, "a second plan would write again".
    • Debug logging in host.readPair traced every one of those to netlink.VethPeerIndex on the tenant end returning unexpected EOF. Both ends existed with the right alias, VRF and ifindex at the time.
    • In isolation, a plain veth in an empty netns with no XDP attached, netlink.VethPeerIndex fails about once in 300,000 to 1,000,000 calls. The string-set count from ETHTOOL_GSSET_INFO reads back as 0.

    So all three failures in this issue share one cause. readPair (internal/worker/local/kernel.go) confirms the pair's peer through two SIOCETHTOOL ioctls. When that lookup fails transiently, readPair reports the pair missing, and then:

    1. Read reports the pair Pending.
    2. Plan reports it missing.
    3. A real Apply calls createPair, which deletes and recreates the live pair. The alias matches, so the collision guard doesn't stop it. Outside the tests, that tears down a working NAT handoff.

    The routed-link path (readRouted and the routed-link creation) and cmd/galactic-nat's tenantEndMAC use the same call.

    I suspect the lookup fails inside the library's ioctl handling, but I haven't proven that. Its request struct is 24 bytes, while the kernel's struct ifreq is 40.

  5. privateip commented on Nov 21, 2026

    @privateip
    ContributorAuthor

    Approved fix plan:

    Fix. Confirm a veth's peer from the netlink link dump Local already reads, instead of an ethtool ioctl. A veth reports its peer's ifindex as IFLA_LINK (Attrs().ParentIndex). IFLA_LINK_NETNSID is absent when the peer is in the same netns.

    • readPair requires each end's ParentIndex to name the other, with both ends in this netns.
    • readRouted, routed-link creation, and the routed handoff report read the pod end's index from ParentIndex. readRouted keeps its existing netns-id check.
    • cmd/galactic-nat tenantEndMAC resolves the tenant end through the NAT end's ParentIndex.

    Tests.

    • Unprivileged unit tests for peer matching: matched, mismatched, and peer in another netns.
    • A steady-state root test: a ready rig, then about 200 consecutive Read and dry-run Plan passes, asserting Ready and an empty plan each time. Without stress it catches the flake only by chance.
    • The existing assertions stay unchanged.

    Verification. Lint, build, unit and root unit tests. The stressed steady-state loop before and after. At least 200 consecutive stressed root runs each of TestUntrustedEntryRoot, TestHookWithdrawalAndRepairRoot and TestEntryPathsRoot/vlan-generic.

    Risk. Low. Same checks, read from the same snapshot, with one fewer syscall per link. No API or config change.

  6. privateip commented on Nov 21, 2026

    @privateip
    ContributorAuthor

    Fixed by #1481, merged into integration/galactic-worker as e9888da. Local and galactic-nat now read a veth's peer from the link list, with no ethtool lookup. Under CPU stress, the three tests named here each passed 200 consecutive runs as root.

  7. privateip commented on Nov 21, 2026

    @privateip
    ContributorAuthor

    Reopening: the fix in #1481 doesn't cover every cause. The new TestSteadyStateRoot failed in CI on another PR's branch, which contains #1481 unchanged plus unrelated galactic-nat changes:

    lifecycle_root_test.go:68: pass 20: VPC 0000081: a plan would write again

    That was the Unit Tests (root) job, run 44900401233, attempt 1. The test passes locally 15 of 15 runs. The failure message doesn't say which object the plan wanted to rewrite, so the next step is to make the test report the planned writes on failure, then find the remaining nondeterministic read.

  8. added 3 commits that reference this issue on Nov 24, 2026
    9c41cdf
    f79de3f
    c09f69b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions