Skip to content

feat: better autorenewal #305

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

Merged
merged 1 commit into from
Jul 4, 2025
Merged

Conversation

k3-cat
Copy link
Contributor

@k3-cat k3-cat commented Jun 29, 2025

Background

Currently tokens only get renewed when they are expiring within next 24 hours. This requires users to login at least once per day to keep them loged in -- which can be really inconvenient.

Changes & Reasons

This PR allow tokens to be renewed when their remaining lifetime is less than a third of the configured value. The threshold a third is come from those common certificate autorenewal configuretions -- for example, the default config of certbot.

@trofen
Copy link
Contributor

trofen commented Jun 30, 2025

I agree that the current automatic token update doesn't work as well as expected, but this pr is not the best solution either. I would suggest @lejianwen to merge it, but consider a better solution in the future

@k3-cat
Copy link
Contributor Author

k3-cat commented Jun 30, 2025

Absolutely not. It's just intended to make a little improvement while minimize impact on existing config/db/code and keep performance overhead low (which is why I use raw milliseconds, and hence integer division).

Still, I doubt there would be an ideal solution for rustdesk - since it only uses a single access token and lack of refreshing mechanisms - but I do have some ideas about it:

  • Use a layer of in-memory cache (radius would work, but probably overkilled, something like go-cache would suffice) to temporarily hold checked tokens
  • When a user accesses the API, store a timestamp to the cache - the cache is key-value based; "key" is the token, and "value" is the timestamp
  • Having a task that periodically read the record from the cache, calculate a new expiration time, and write to the database
  • When the cache expires (either due to timer or lur), immediately execute the previous flow

This is a pretty trivial approach... but...
Pros: easy to implement, tokens can be rolled smoothly
Cons: cache hell, need to manually manage cache state, too many extra components

@lejianwen lejianwen merged commit 17dcff4 into lejianwen:master Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants