ipn/store: make WriteState(id, nil) delete key instead of adding nil entry (#19920)

All StateStore implementations store a nil value in the cache map when WriteState is called with a nil byte slice instead of deleting the key. This causes ReadState to return (nil, nil) instead of (nil, ErrStateNotExist), since the key is still present in the map.

This breaks reset-auth in Windows, Linux, and Android, and the node can't log back in without manually editing the state file. (macOS uses a different state store)
DeleteProfile, DeleteAllProfilesForUser, setUnattendedModeAsConfigured are impacted but don't seem to break because the deleted keys are not reread.

This deletes the key from the cache instead.

Fixes tailscale/corp#42477

Signed-off-by: kari-ts <kari@tailscale.com>
This commit is contained in:
kari-ts
2026-05-29 11:22:14 -07:00
committed by GitHub
parent 3d5102090f
commit 7355116c05
9 changed files with 194 additions and 10 deletions
+5 -2
View File
@@ -243,8 +243,11 @@ func (s *tpmStore) WriteState(k ipn.StateKey, bs []byte) error {
if bytes.Equal(s.cache[k], bs) {
return nil
}
s.cache[k] = bytes.Clone(bs)
if bs == nil {
delete(s.cache, k)
} else {
s.cache[k] = bytes.Clone(bs)
}
return s.writeSealed()
}