Skip to content

tailcat: stop trusting a restarted client's old direct path - #208

Merged
bradfitz merged 1 commit into
mainfrom
bradfitz/meow-instance
Dec 2, 2026
Merged

bradfitz merged 1 commit into
mainfrom
bradfitz/meow-instance

Conversation

@bradfitz

@bradfitz bradfitz commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

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

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>
@bradfitz
bradfitz merged commit 1fde774 into main Dec 2, 2026
11 checks passed
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

1 participant