Stale (Machine) objects are written back to database #27

Closed
opened 2025-12-29 01:20:19 +01:00 by adam · 2 comments
Owner

Originally created by @kradalby on GitHub (Aug 21, 2021).

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.

5b1b40ce93/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:

  1. headscale is running, and client1 has a longpolling session
  2. Admin uses headscale cli to enable an advertised route on client1
  3. A keepalive is sent to client1, updating the lastSeen field on its already loaded Machine object.
  4. 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.

Originally created by @kradalby on GitHub (Aug 21, 2021). 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: 1. headscale is running, and client1 has a longpolling session 2. Admin uses `headscale` cli to enable an advertised route on client1 3. A keepalive is sent to client1, updating the lastSeen field on its already loaded `Machine` object. 4. 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.
adam added the enhancementstale labels 2025-12-29 01:20:19 +01:00
adam closed this issue 2025-12-29 01:20:19 +01:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 14, 2023):

This issue is stale because it has been open for 180 days with no activity.

@github-actions[bot] commented on GitHub (Oct 14, 2023): This issue is stale because it has been open for 180 days with no activity.
Author
Owner

@github-actions[bot] commented on GitHub (Oct 29, 2023):

This issue was closed because it has been inactive for 14 days since being marked as stale.

@github-actions[bot] commented on GitHub (Oct 29, 2023): This issue was closed because it has been inactive for 14 days since being marked as stale.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#27