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

Clock drift mitigation suggestion not working #121

Open
joknu1 opened this issue Aug 30, 2019 · 11 comments
Open

Clock drift mitigation suggestion not working #121

joknu1 opened this issue Aug 30, 2019 · 11 comments

Comments

@joknu1
Copy link

joknu1 commented Aug 30, 2019

Under Clock drift and the need for Re-syncing the following is stated:

rerun the TrueTime.init call at regular/frequent intervals so you resynchronize with the true time

However looking at the lib code gives:

    protected void initialize(String ntpHost) throws IOException {
        if (isInitialized()) {
            TrueLog.i(TAG, "---- TrueTime already initialized from previous boot/init");
            return;
        }
        requestTime(ntpHost);
        saveTrueTimeInfoToDisk();
    }

which effectively skips fetching new time from NTP if value already cached in RAM. (I'm not using saving to prefs option.)

So how can I make the lib sync time every now and then?

@Boucaa
Copy link

Boucaa commented Feb 24, 2020

I came across the same issue, @joknu1 have you found a workaround for this?
My only idea is to clear the cache, but this way I lose the ability to check the time until a new initialization goes through successfully.

@joknu1
Copy link
Author

joknu1 commented Feb 27, 2020

I came across the same issue, @joknu1 have you found a workaround for this?
My only idea is to clear the cache, but this way I lose the ability to check the time until a new initialization goes through successfully.

No, I didn't. I still use this lib, but since the project I'm working on only cares for drift in the scale of 1 hour, it does not seem critical for our project's purpose. Le t me know if you find any workaround @Colanderr !

@john-stemberger
Copy link

I have created a kotlin extension as a work around for this issue if anyone is interested

https://gist.github.com/john-stemberger/bab63c3935cdda052d2baf92732a2b85

@Matt7170
Copy link

How do I register for True time as a new instacart shopper?

@stAyushJain
Copy link

stAyushJain commented Feb 18, 2023

@kaushikgopal Need your help. we are using vanilla version in our app and Re-sync seems impossible if cache option is enabled. Which method should I use to do re-sync in vanilla version?. Because requestTime(ntpHost) is a package-private in 'TrueTime'.

I am using below solution

class CustomCacheCacheImpl (private val doingResync: Boolean): CacheInterface {
  ...
  ...
   override fun get(key: String?, defaultValue: Long): Long {
          // On Force Sync return 0 so that {isInitialized()} will return false.
          if (doingResync && key.equals(CacheInterface.KEY_CACHED_BOOT_TIME)) return 0
          return _sharedPreferences.getLong(key, defaultValue)
    }
   

@liu0527aa
Copy link

如果有人感兴趣的话,我已经创建了一个 kotlin 扩展作为解决此问题的方法

https://gist.github.com/john-stemberger/bab63c3935cdda052d2baf92732a2b85

hello,i want to use you method. However, it can't be allowed to change this code as the library. Could you tell the solition

@stAyushJain
Copy link

@liu0527aa you can try alpha version of truetime. There you do not need to use requestTime(ntpHost). Or else you can use mine approach where you need to use custom implementation of Cache and update key KEY_CACHED_BOOT_TIME manually.

@liu0527aa
Copy link

@liu0527aa you can try alpha version of truetime. There you do not need to use requestTime(ntpHost). Or else you can use mine approach where you need to use custom implementation of Cache and update key KEY_CACHED_BOOT_TIME manually.

I feel very embarrassed to ask where can i find the alpha version of truetime。。。And how to use the alpha version

@stAyushJain
Copy link

4.0.0.alpha @liu0527aa

Screenshot 2023-08-10 at 5 41 59 PM

@liu0527aa
Copy link

4.0.0.alpha@liu0527aa

屏幕截图 2023-08-10 下午 5 41 59

yes,i find it。however, when i use the library of 4.0.0. I met this mistake,the author didn't push the 4.0.0.alpha to jitpack.io。could u give me some suggestion? thanks!
image

@CyxouD
Copy link

CyxouD commented Feb 21, 2024

At 3.5 version, I fix this by calling .initializeNtp instead of .initializeRx. initializeNtp is called internally by .initializeRx if TrueTimeRx isn't initialized. It helps to not use cached version during clock re-sync.
It looks like this

TrueTimeRx.build()
                    .initializeNtp(NTP_APPLE)
                    .subscribeOn(Schedulers.io())
                    .map { TrueTimeRx.now() }

Methods implementation:
image

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

No branches or pull requests

7 participants