Repository navigation
tailcat: stop trusting a restarted client's old direct path - #208
Merged
Merged
Conversation
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.
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