-
Notifications
You must be signed in to change notification settings - Fork 533
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
timezone caching prevents updating the timezone #834
Comments
Replying to #728 (comment) :
To propose a solution I'd first have to understand why we need a cache in first place. Is it really that slow to parse the timezone? If we want read and compare the TZ variable on every call, would that prevent the cache from speeding up anything? |
So there's multiple things here:
All of these combined I think warrant having a cache, but maybe if some of the parts aren't needed we wouldn't? Also if you want to create some benchmarks for this we might decide we don't need (as much) caching. I seem to remember maybe @esheppa did some benchmarking, but can't find it now... |
I think there are a few competing issues here:
There are a couple of options here:
As another potential option available now, if you listen for the | I seem to remember maybe @esheppa did some benchmarking, but can't find it now... I don't thing I did this with #728, but I'd definitely like to do it in combination with any further changes to the caching strategy |
I think this is pretty reasonable. What we've got is a decent first pass, but now that we know people do actually change the |
changing the Here's also some useful notes I extracted from our code
It seems that in my case I actually only have an issue during unit tests where TZ is explicitly set to a temporary path. Still, I think replicating glibcs behavior is useful for the reasons above. |
After looking at #853 I had some more insights: This has a lot of flaws:
|
I'm a little unsure about the conclusions to draw from your stated flaws. Do you think the solution #853 would solve your issue? |
#853 would solve my specific usecase because my app is single threaded (tokio using the The fact that "force re-reading TZ" is library-specific isn't an issue, it's simply inconvenient because it prevents me from creating a public crate that "simply works" no matter how you get your localtime. |
Note that in the solution proposed in #853, I don't think there's a need to "force re-reading TZ": any operation involving the |
If I understand the code correctly, that's not true for the case I described where TZ points to a symlink. timedatectl will change the symlink so updating |
@M1cha - my assumption here is that in the case where TZ points to a symlink, it will be However this style of API may suit better as you can then implement your own cache invalidation customized to your specific use case (listening to d-bus message, checking environment variable, checking symlink mtime, etc, etc): #830 (comment) RE. sharing on all threads - each thread has its own cache will will update after expiry (1 second). I think implementing an |
IMO the actual path is system-specific and this library should not rely on it other than using The Timezone API does indeed sound better to me since I wouldn't have to force-update anything and could instead simply let the code that is affected by the timezone change always read the timezone without any caching.
Both of these usecases would be fine with simply never using caching because their codepaths don't run often so they can't suffer from bad performance. |
#1457 should be able to fix this. |
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.
Once that happened we need to make sure that
localtime_r
returns the updated value. The issue is that glibc caches the value, too. The difference is that they update it when the value ofTZ
has changed. So we can simply change the value, call tzset, change the value back, call tzset again.That hack basically works for C and worked for chrono too because it always called
localtime_r
. Since that's not the case anymore, the change doesn't propagate to chrono anymore. So basically we need a way to propagate a timezone change to chrono.Originally posted by @M1cha in #728 (comment)
The text was updated successfully, but these errors were encountered: