instacart / truetime-android

Android NTP time library. Get the true current time impervious to device clock time changes
https://tech.instacart.com/truetime/
Apache License 2.0
1.41k stars 194 forks source link

Bad locking causing deadlocks. #74

Closed fifteenhex closed 6 years ago

fifteenhex commented 6 years ago

If the library is initialized asynchronously like with initializeRx() a deadlock happens if you try to get the time before initialization has completed because the initialization process and the check for initialization want to lock the SntpClient instance.

Maybe change the initialized flag to an AtomicBoolean so it has it's own locking?

danielpsantiago commented 6 years ago

getting the same error here

cmagnuson commented 6 years ago

Seeing the same here - with a poor connection, SntpClient.requestTime locks SntpClient which causes calls to wasInitialized() from UI thread to block for a very long time

kaushikgopal commented 6 years ago

apologies for replying so late. I actually have had a branch kg/fix/sync_to_atomic for sometime that should address this.

PR #80 should address this.

Alternatively, you can try importing that branch directly and seeing if it addresses your issue.

kaushikgopal commented 6 years ago

master should have the required fixes now. If you're eager to take this before it hits 3.4 try:

implementation com.github.instacart.truetime-android:library-extension-rx:09087b6a6e

kaushikgopal commented 6 years ago

closing this out as I'm hoping the newer version of this lib has resolved this issue

after-ephemera commented 5 years ago

Updating to 3.4 fixed the issue for me.