From 62f31306376ca860ef7b68c55a4d8874aabc4f26 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 16 Sep 2026 18:02:32 +0000 Subject: [PATCH] tstest/integration: deflake TestNATPing TestNATPing called SetMasqueradeAddresses on the test control server and then immediately read both nodes' status, expecting the new masqueraded peer addresses to already be there. But the change reaches the nodes asynchronously via their streaming map responses, so under load the status check ran before the new map response arrived and the test failed with "n1 sees n2 as 100.64.0.2; want 100.64.2.1" and the like. This was the dominant failure mode on the flakes dashboard (11 of the 18 most recent CI failures) and the only one found in a six hour Antithesis run (run 30b4de27d89d8d7a651e7b43b3f1ec3f-61-9, 54 failures in 16,599 runs). Wait for each node's status to report the expected peer address instead. Also retry the "tailscale ping" invocations, since a ping can fail transiently right after a map response changes a peer's addresses and before the engine is reconfigured; the second most common failure mode was pings exiting with status 1. Failed pings now include the CLI output in the error rather than a bare exit status. Locally, flakestress (32 workers) reproduced the failure in 29 of 210 runs before this change (13.8%) and in 0 of 1,173 runs after. The remaining Windows-only failure mode on the dashboard, TempDir cleanup failing because tailscaled.exe is still open, is a harness-wide issue that affects every integration test and is not specific to this test. Fixes #12169 Updates tailscale/corp#47865 Change-Id: I7c3e2b8a5d914f0e6a2b1c9d8e7f6a5b4c3d2e1f Signed-off-by: Brad Fitzpatrick --- tstest/integration/integration_test.go | 81 ++++++++++++++++---------- 1 file changed, 49 insertions(+), 32 deletions(-) diff --git a/tstest/integration/integration_test.go b/tstest/integration/integration_test.go index 385d4965a..fcfca24eb 100644 --- a/tstest/integration/integration_test.go +++ b/tstest/integration/integration_test.go @@ -1457,7 +1457,6 @@ func TestClientSideJailing(t *testing.T) { // TestNATPing creates two nodes, n1 and n2, sets up masquerades for both and // tries to do bi-directional pings between them. func TestNATPing(t *testing.T) { - flakytest.Mark(t, "https://github.com/tailscale/tailscale/issues/12169") tstest.Parallel(t) for _, v6 := range []bool{false, true} { env := NewTestEnv(t) @@ -1543,42 +1542,60 @@ func TestNATPing(t *testing.T) { }, } + // awaitPeerIP waits for n's status to report the peer with node + // key peer as having the Tailscale IP want. Masquerade changes + // reach the nodes asynchronously via their streaming map + // responses, so the status can't be checked immediately after + // SetMasqueradeAddresses. + awaitPeerIP := func(t *testing.T, n *TestNode, peer key.NodePublic, want netip.Addr) { + t.Helper() + if err := tstest.WaitFor(20*time.Second, func() error { + st, err := n.Status() + if err != nil { + return err + } + ps, ok := st.Peer[peer] + if !ok { + return fmt.Errorf("peer %v not in status", peer.ShortString()) + } + if !slices.Contains(ps.TailscaleIPs, want) { + return fmt.Errorf("peer %v has IPs %v; want %v", peer.ShortString(), ps.TailscaleIPs, want) + } + return nil + }); err != nil { + t.Fatal(err) + } + } + + // ping runs "tailscale ping" with the provided arguments from n, + // retrying on failure. A ping can fail transiently right after a + // map response changes the peer's addresses, before the engine + // has been reconfigured with the new netmap. + ping := func(t *testing.T, n *TestNode, args ...string) { + t.Helper() + args = append([]string{"ping"}, args...) + if err := tstest.WaitFor(30*time.Second, func() error { + out, err := n.TailscaleForOutput(args...).CombinedOutput() + if err != nil { + return fmt.Errorf("tailscale %v: %v; output: %s", args, err, out) + } + return nil + }); err != nil { + t.Fatal(err) + } + } + for _, tc := range tests { t.Run(fmt.Sprintf("v6=%t/%v", v6, tc.name), func(t *testing.T) { env.Control.SetMasqueradeAddresses(tc.pairs) - ipIdx := 0 - if v6 { - ipIdx = 1 - } + awaitPeerIP(t, n1, k2, tc.n1SeesN2IP) + awaitPeerIP(t, n2, k1, tc.n2SeesN1IP) - s1 := n1.MustStatus() - n2AsN1Peer := s1.Peer[k2] - if got := n2AsN1Peer.TailscaleIPs[ipIdx]; got != tc.n1SeesN2IP { - t.Fatalf("n1 sees n2 as %v; want %v", got, tc.n1SeesN2IP) - } - - s2 := n2.MustStatus() - n1AsN2Peer := s2.Peer[k1] - if got := n1AsN2Peer.TailscaleIPs[ipIdx]; got != tc.n2SeesN1IP { - t.Fatalf("n2 sees n1 as %v; want %v", got, tc.n2SeesN1IP) - } - - if err := n1.Tailscale("ping", tc.n1SeesN2IP.String()).Run(); err != nil { - t.Fatal(err) - } - - if err := n1.Tailscale("ping", "-peerapi", tc.n1SeesN2IP.String()).Run(); err != nil { - t.Fatal(err) - } - - if err := n2.Tailscale("ping", tc.n2SeesN1IP.String()).Run(); err != nil { - t.Fatal(err) - } - - if err := n2.Tailscale("ping", "-peerapi", tc.n2SeesN1IP.String()).Run(); err != nil { - t.Fatal(err) - } + ping(t, n1, tc.n1SeesN2IP.String()) + ping(t, n1, "-peerapi", tc.n1SeesN2IP.String()) + ping(t, n2, tc.n2SeesN1IP.String()) + ping(t, n2, "-peerapi", tc.n2SeesN1IP.String()) }) } }