headscale
headscale copied to clipboard
Stale (Machine) objects are written back to database
There is a series of calls to h.db.Save around the code which is typically done on long living Machine objects loaded/created when the map endpoint (longpolling) is opened.
https://github.com/juanfont/headscale/blob/5b1b40ce93ffb5f2540449e94562cb9dc98e3267/poll.go#L51-L53
By calling save on this object, sometimes with only a single change (e.g. last seen), a potentially stale object is written to the database.
This becomes apparent when you use the CLI to modify Machines, where the next update from the server will revert your change.
For example:
- headscale is running, and client1 has a longpolling session
- Admin uses
headscalecli to enable an advertised route on client1 - A keepalive is sent to client1, updating the lastSeen field on its already loaded
Machineobject. - Machine object is saved, not containing the route change from the CLI, effectively reverting the change.
We should probably get all the database calls out of the code, and into some helper functions so we can control the behaviour from a single place.