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

Intialization failed with coroutine but works with rx on first time #160

Open aashi-09 opened 4 months ago

aashi-09 commented 4 months ago

I was trying to run the source code version 4.0.0 and in demo app it got initialised with rx java but throws error for coroutines. After a while only it works.

Expected : If it is working with rx in first go it should work with coroutine also. Device : Samsung galaxy m31s, Android version 12.

Attaching a logs for reference.

`SNTP request failed java.net.SocketTimeoutException: Poll timed out at libcore.io.IoBridge.poll(IoBridge.java:866) at java.net.PlainDatagramSocketImpl.doRecv(PlainDatagramSocketImpl.java:151) at java.net.PlainDatagramSocketImpl.receive0(PlainDatagramSocketImpl.java:142) at java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:164) at java.net.DatagramSocket.receive(DatagramSocket.java:849) at com.instacart.truetime.sntp.SntpImpl.requestTime(SntpImpl.java:136) at com.instacart.truetime.time.TrueTimeImpl.sntpRequest(TrueTimeImpl.kt:143) at com.instacart.truetime.time.TrueTimeImpl.requestTime(TrueTimeImpl.kt:129) at com.instacart.truetime.time.TrueTimeImpl.initialize(TrueTimeImpl.kt:77) at com.instacart.truetime.time.TrueTimeImpl.access$initialize(TrueTimeImpl.kt:15) at com.instacart.truetime.time.TrueTimeImpl$sync$1.invokeSuspend(TrueTimeImpl.kt:30) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42) at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)

Screenshot 2024-04-30 at 1 02 53 PM

Screenshot_20240430-130417_TrueTime (Sample) for Android `

aashi-09 commented 4 months ago
Screenshot 2024-04-30 at 1 02 53 PM

Screenshot_20240430-130417_TrueTime (Sample) for Android

ShowMe01 commented 2 months ago

I have same problem, that's because kotlin's version use "time.apple.com" while rx use "time.google.com".

And apple's ntp server may slower than google, so socket connection timeout.

Change them into same ntp host.