1
0
mirror of https://github.com/juanfont/headscale.git synced 2025-09-25 17:51:11 +02:00

mapper: simplify online status

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2025-09-16 09:43:28 +02:00
parent 7f469714ed
commit 44273e531f
No known key found for this signature in database

View File

@ -88,16 +88,9 @@ func generateMapResponse(nodeID types.NodeID, version tailcfg.CapabilityVersion,
// TODO(kradalby): This can potentially be a peer update of the old and new subnet router. // TODO(kradalby): This can potentially be a peer update of the old and new subnet router.
mapResp, err = mapper.fullMapResponse(nodeID, version) mapResp, err = mapper.fullMapResponse(nodeID, version)
} else { } else {
// CRITICAL FIX: Read actual online status from NodeStore when available, // Trust the change type for online/offline status to avoid race conditions
// fall back to deriving from change type for unit tests or when NodeStore is empty // between NodeStore updates and change processing
var onlineStatus bool onlineStatus := c.Change == change.NodeCameOnline
if node, found := mapper.state.GetNodeByID(c.NodeID); found && node.IsOnline().Valid() {
// Use actual NodeStore status when available (production case)
onlineStatus = node.IsOnline().Get()
} else {
// Fall back to deriving from change type (unit test case or initial setup)
onlineStatus = c.Change == change.NodeCameOnline
}
mapResp, err = mapper.peerChangedPatchResponse(nodeID, []*tailcfg.PeerChange{ mapResp, err = mapper.peerChangedPatchResponse(nodeID, []*tailcfg.PeerChange{
{ {
@ -108,8 +101,9 @@ func generateMapResponse(nodeID types.NodeID, version tailcfg.CapabilityVersion,
} }
case change.NodeNewOrUpdate: case change.NodeNewOrUpdate:
// If the node is the one being updated, we send a "full" self update // If the node is the one being updated, we send a self update that preserves peer information
// to ensure the node sees changes to its own properties (e.g., hostname/DNS name changes) // to ensure the node sees changes to its own properties (e.g., hostname/DNS name changes)
// without losing its view of peer status during rapid reconnection cycles
if c.IsSelfUpdate(nodeID) { if c.IsSelfUpdate(nodeID) {
mapResp, err = mapper.selfMapResponse(nodeID, version) mapResp, err = mapper.selfMapResponse(nodeID, version)
} else { } else {