ipn/ipnlocal: resend UserProfiles to IPN bus watchers after a profile change

A watch session's UserProfiles dedup state was only reset when the
self node delivered to it changed, as of c9fb05b6f5. Switching to
a profile that never gets a self node, such as a stopped or logged
out one, and back delivered the same self node again, so the profiles
were not resent to watchers that had dropped them on the switch. The
Windows GUI then listed no tagged or other users' devices.

Reset the dedup state on a profile change as well.

Updates #19889
Updates tailscale/corp#51597

Signed-off-by: Nick Khyl <[email protected]>
This commit is contained in:
Nick Khyl authored and Nick Khyl committed 2026-11-16 18:54:54 -08:00
1 parent 203692da0a
commit 13af579d64
2 files changed
+45

No files matched your search

+10
View File
@@ -207,6 +207,8 @@ type watchSession struct {
// this session via [Notify.SelfChange]. A change to self is a profile
// boundary for implicit bus state, so per-session dedup state such as
// lastSentUserProfile must be reset when this identity changes.
// It is itself reset on a profile change, as the new profile may
// have no self node.
lastSentSelf tailcfg.NodeView
// policyUID is the user ID used for policy snapshot scoping.
@@ -8824,6 +8826,14 @@ func (b *LocalBackend) resetForProfileChangeLocked() error {
return nil
}
b.closeDiskCacheLocked()
// IPN bus watchers may drop the old node's implicit bus state
// on a profile switch, and the new profile may never deliver
// a self node to mark the boundary, such as when the new profile's
// node key has expired.
for _, sess := range b.notifyWatchers {
sess.lastSentUserProfile = nil
sess.lastSentSelf = tailcfg.NodeView{}
}
if buildfeatures.HasDNS {
if dm, ok := b.sys.DNSManager.GetOK(); ok {
dm.Resolver().ClearNegativeCache()
+35
View File
@@ -3316,6 +3316,41 @@ func TestNotifyForSessionUserProfilesDedupResetsOnSelfChange(t *testing.T) {
}
}
// TestNotifyForSessionUserProfilesDedupResetsOnProfileChange tests that
// user profiles are resent after switching to a profile that never gets
// a self node, such as a logged out one, and back.
func TestNotifyForSessionUserProfilesDedupResetsOnProfileChange(t *testing.T) {
b := newTestLocalBackend(t)
sess := &watchSession{
sessionID: "test-session",
ctx: t.Context(),
mask: ipn.NotifyPeerChanges,
ch: make(chan *ipn.Notify, 100),
}
self := &tailcfg.Node{ID: 1, StableID: "self", User: 10}
profiles := map[tailcfg.UserID]tailcfg.UserProfileView{
10: (&tailcfg.UserProfile{ID: 10, LoginName: "[email protected]", DisplayName: "Alice"}).View(),
11: (&tailcfg.UserProfile{ID: 11, LoginName: "tagged-devices", DisplayName: "Tagged Devices"}).View(),
}
b.mu.Lock()
defer b.mu.Unlock()
mak.Set(&b.notifyWatchers, sess.sessionID, sess)
n := b.notifyForSessionLocked(sess, &ipn.Notify{SelfChange: self, UserProfiles: profiles})
if got, want := len(n.UserProfiles), len(profiles); got != want {
t.Fatalf("initial UserProfiles len = %d; want %d", got, want)
}
if err := b.resetForProfileChangeLocked(); err != nil {
t.Fatal(err)
}
n = b.notifyForSessionLocked(sess, &ipn.Notify{SelfChange: self, UserProfiles: profiles})
if got, want := len(n.UserProfiles), len(profiles); got != want {
t.Fatalf("UserProfiles len after profile change = %d; want %d", got, want)
}
}
// tests LocalBackend.updateNetmapDeltaLocked
func TestUpdateNetmapDelta(t *testing.T) {
b := newTestLocalBackend(t)