Repository navigation
Conversation
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>
Member
|
I forked this off into #208, tweaked a bit, but mostly taking your test as-is. |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,onMeowupdates the node'sDiscoKeyand pushes the new netmap, so magicsock drops its trust in the old process's direct path instead of sending the WireGuard handshake response there.TestClientRestartSameKeyrestarts a client twice with the same node key and checks that the server stops using the old path. It uses a newMeowForTesthelper in export_test.go. The test fails without the change on Windows and Linux.