Skip to content

tailcat: give each Client a fresh disco key - #201

Closed
cnupy wants to merge 1 commit into
tailscale:mainfrom
cnupy:fresh-client-disco-key
Closed

cnupy wants to merge 1 commit into
tailscale:mainfrom
cnupy:fresh-client-disco-key

Conversation

@cnupy

@cnupy cnupy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #199

A client now gets a fresh disco key for each Client, and the server derives its own from its node key as before. When a known client sends a meow with a different disco key, onMeow updates the node's DiscoKey and pushes the new netmap, so magicsock drops its trust in the old process's direct path instead of sending the WireGuard handshake response there.

TestClientRestartSameKey restarts a client twice with the same node key and checks that the server stops using the old path. It uses a new MeowForTest helper in export_test.go. The test fails without the change on Windows and Linux.

A client's disco key was derived from its node key, so a client process
that restarted with the same key file came back with the same disco key.
The server's onMeow returned early for a known client, so the server's
magicsock kept the old process's direct UDP path. Its WireGuard
handshake response went to that dead port, and the new client only got
through on the handshake retry, about 5 s later.

Clients now use a fresh disco key per Client. The server still derives
its disco key from its node key, since that key is part of its address.
When a known client sends a meow with a new disco key, onMeow updates
the key in the netmap, so magicsock drops the old path and replies go
through DERP until the new direct path is found.

TestClientRestartSameKey restarts a client twice with the same node key
after it has a direct path. Each time it hands the new process's meow to
the server before the client goes on the network (MeowForTest) and
checks that the server stops using the old address, then dials. Handing
over the meow first keeps the test from depending on how fast the new
client advertises its endpoints, which hid the bug on Linux.

Fixes tailscale#199

Signed-off-by: cnupy <38653063+cnupy@users.noreply.github.com>
@bradfitz

bradfitz commented Dec 2, 2026

Copy link
Copy Markdown
Member

I forked this off into #208, tweaked a bit, but mostly taking your test as-is.

@bradfitz bradfitz closed this Dec 2, 2026
bradfitz added a commit that referenced this pull request Dec 2, 2026
A client's disco key is derived from its node key, so a client process
that restarts with the same key file comes back with the same disco
key. The server's onMeow returned early for a known client, so the
server's magicsock kept trusting the old process's direct UDP path. Its
WireGuard handshake response went to that dead port, and the new client
only got through on the handshake retry, about 5 s later.

Clients now append a random 8-byte instance ID, one per Client, to their
meow pings. When a known client's meow carries a different instance ID,
the server makes magicsock stop trusting its direct path, so replies
also go over DERP until a new direct path is confirmed. A retried meow
or a later Ping from the same Client repeats the ID and keeps a good
path.

To reset the path, the server upserts the peer into magicsock with a
throwaway disco key and then with the real one, which reuses magicsock's
handling of a peer whose disco key changed. Removing and re-adding the
peer doesn't work: the WireGuard peer keeps sending through the removed
magicsock endpoint.

PR #201 instead gave each Client a fresh disco key, but then a new client
restarting against an older server would be stuck on DERP: the old
server keeps the first disco key it saw. With the instance ID, every
mix of old and new clients and servers behaves at least as before. Old
servers ignore the extra bytes, as ParseMeowPing always has, and old
clients send none, so new servers never reset their paths.

Measured with the tailcat binary on a local DERP, eight restarts of a
client process sharing one saved key took 0.07 s each with a new client
and server. Every other mix of old and new still took about 5 s on two
or three of the eight.

TestClientRestartSameKey and the MeowForTest helper are from PR #201,
along with the diagnosis. The test now also checks that a repeated meow
from the same Client keeps its direct path.

Fixes #199

Co-authored-by: cnupy <38653063+cnupy@users.noreply.github.com>
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A client that restarts with the same node key takes about 5 s to connect

2 participants