diff --git a/machine.go b/machine.go index d94fb004..d0be2df7 100644 --- a/machine.go +++ b/machine.go @@ -420,14 +420,18 @@ func (h *Headscale) isOutdated(machine *Machine) bool { } lastChange := h.getLastStateChange(namespaces...) + lastUpdate := machine.CreatedAt + if machine.LastSuccessfulUpdate != nil { + lastUpdate = *machine.LastSuccessfulUpdate + } log.Trace(). Caller(). Str("machine", machine.Name). - Time("last_successful_update", *machine.LastSuccessfulUpdate). - Time("last_state_change", lastChange). + Time("last_successful_update", lastChange). + Time("last_state_change", lastUpdate). Msgf("Checking if %s is missing updates", machine.Name) - return machine.LastSuccessfulUpdate.Before(lastChange) + return lastUpdate.Before(lastChange) } func (machine Machine) String() string { diff --git a/poll.go b/poll.go index 94c60dc1..883aa621 100644 --- a/poll.go +++ b/poll.go @@ -388,10 +388,14 @@ func (h *Headscale) PollNetMapStream( updateRequestsReceivedOnChannel.WithLabelValues(machine.Name, machine.Namespace.Name). Inc() if h.isOutdated(machine) { + var lastUpdate time.Time + if machine.LastSuccessfulUpdate != nil { + lastUpdate = *machine.LastSuccessfulUpdate + } log.Debug(). Str("handler", "PollNetMapStream"). Str("machine", machine.Name). - Time("last_successful_update", *machine.LastSuccessfulUpdate). + Time("last_successful_update", lastUpdate). Time("last_state_change", h.getLastStateChange(machine.Namespace.Name)). Msgf("There has been updates since the last successful update to %s", machine.Name) data, err := h.getMapResponse(machineKey, mapRequest, machine) @@ -448,10 +452,14 @@ func (h *Headscale) PollNetMapStream( h.db.Save(&machine) } else { + var lastUpdate time.Time + if machine.LastSuccessfulUpdate != nil { + lastUpdate = *machine.LastSuccessfulUpdate + } log.Trace(). Str("handler", "PollNetMapStream"). Str("machine", machine.Name). - Time("last_successful_update", *machine.LastSuccessfulUpdate). + Time("last_successful_update", lastUpdate). Time("last_state_change", h.getLastStateChange(machine.Namespace.Name)). Msgf("%s is up to date", machine.Name) }