Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kradalby opened this issue Aug 21, 2021 · 2 comments
Closed

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

kradalby opened this issue Aug 21, 2021 · 2 comments
Labels
enhancement New feature or request stale

Comments

@kradalby
Copy link
Collaborator

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.

headscale/poll.go

Lines 51 to 53 in 5b1b40c

now := time.Now().UTC()
m.LastSeen = &now
h.db.Save(&m)

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.

kradalby added a commit to kradalby/headscale that referenced this issue Aug 21, 2021
We are currently holding Machine objects in memory for a long time,
while waiting for stream/longpoll, this might make us end up with stale
objects, that we just call save on, potentially overwriting stuff in
the database.

A typical scenario would be someone changing something from the CLI,
e.g. enabling routes, which in turn is overwritten again by the stale
object in the longpolling function.

The code has been left with TODO's and a discussion is available in juanfont#93.
kradalby added a commit to kradalby/headscale that referenced this issue Aug 21, 2021
We are currently holding Machine objects in memory for a long time,
while waiting for stream/longpoll, this might make us end up with stale
objects, that we just call save on, potentially overwriting stuff in
the database.

A typical scenario would be someone changing something from the CLI,
e.g. enabling routes, which in turn is overwritten again by the stale
object in the longpolling function.

The code has been left with TODO's and a discussion is available in juanfont#93.
@juanfont juanfont added the enhancement New feature or request label Oct 16, 2021
@kradalby kradalby added this to the v0.17.0 milestone Jun 12, 2022
@kradalby kradalby modified the milestones: v0.17.0, v0.19.0 Oct 28, 2022
@github-actions
Copy link
Contributor

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

@github-actions github-actions bot added the stale label Oct 14, 2023
@github-actions
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale
Projects
None yet
Development

No branches or pull requests

2 participants