-
Notifications
You must be signed in to change notification settings - Fork 544
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
Caching of parsed TimeZone information #728
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start! A bunch of thoughts...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking a lot better, some further suggestions/thoughts!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with one minor issue addressed!
@esheppa would you mind rebasing this? Probably also good to just squash the commits. |
…Z variable minor fixes improve ergonomics, cache mtime for 1s 1.32 fixes avoid excess Cache::default() calls add back cfg_attr
Is this PR not based on the assumption that the system's time zone will never change during the execution of a program? This is certainly not the case — the tzdb being updated by the system is the most obvious situation, but there are others that are far more subtle. |
We invalidate the cache within one second if the mtime of the tzdb file changes. Would be interested to hear more about the subtle scenarios you've considered for your solution in the time crate! |
Ah, invalidating the cache is good and should catch most cases. The When you say the "tzdb file", what are you referring to? The file containing the version? If so, it's possible for someone to write one of the other files directly. I don't blame you if you say "too bad" in that situation, but it's something to be mindful of. |
The symlink metadata, see here: https://github.com/chronotope/chrono/pull/728/files#diff-568a8cdf0e0b7a4922b13d27771df35ac8e561ac9f25c5229263120edc171486R51. We're explicitly leaving the |
In a proprietary project we're currently locked to chrono 0.4.19 because the recent addition of caching the timezone broke our code. I have to admit that the way we propagate the change to chrono is quite hacky and that we're relying on implementation details of both glibc and chrono. So first of: yes, the TZ variable points to a symlink which systemd changes after updating the timezone. This is even the case on desktop arch linux. So basically we're using dbus to listen for timezone changes that come from systemd-timesyncd. That hack basically works for C and worked for chrono too because it always called |
@M1cha please file a new issue, or better yet, propose some code changes (likely around https://github.com/chronotope/chrono/blob/main/src/offset/local/unix.rs#L41) that would fix your issue as a PR. I'm surprised that it doesn't work, we designed the caching approach to be responsive to approaches such as yours. |
This is a basic implementation of caching as described in #719