mirror of
https://github.com/tailscale/tailscale.git
synced 2026-07-14 17:43:03 -04:00
Add TestRangeHook, a build-tagged (ts_rangehook) test that finds
accidentally-O(n) range loops in the netmap delta processing path.
It arms the runtime.DidRange hook, a Tailscale-only Go toolchain
modification that reports every range loop's potential and actual
iteration counts, while an in-process tsnet client (via the existing
largetailnet Streamer harness) processes a few hundred one-peer
add+remove deltas against an initial N-peer netmap. Any loop that
could iterate at least N/2 times is recorded with its call stack
into a custom pprof profile, so per-delta O(n) work shows up as a
stack with a sample count near the delta count.
The test requires the bradfitz/rangehook branch of
github.com/tailscale/go (as of 2026-07-11, based on upstream Go at
approximately 1.27rc1), which is why it is hidden behind the
ts_rangehook build tag; the stock toolchain has no runtime.DidRange
and cannot compile this file. See the file comment for the full
recipe.
Running it on main at 296f6c1f7 finds 16 unique per-delta O(n)
loops, all under LocalBackend.UpdateNetmapDelta ->
authReconfigLocked; on bradfitz/routeman2 that drops to 6.
Updates #12542
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Change-Id: I49ccadbd4472abecc1450ca67bd93919f6b90201