truetime-android
truetime-android copied to clipboard
android.system.ErrnoException on SntpClient
Using the 3.4
Rx version of the lib, with initializeNtp
I get this error android.system.ErrnoException sendto failed: EPERM (Operation not permitted)
. This happens with a lot of Android versions and device brands.
Caused by android.system.ErrnoException: sendto failed: EPERM (Operation not permitted)
at libcore.io.Linux.sendtoBytes(Linux.java)
at libcore.io.Linux.sendto(Linux.java:225)
at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:304)
at libcore.io.IoBridge.sendto(IoBridge.java:569)
at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:124)
at java.net.DatagramSocket.send(DatagramSocket.java:721)
at com.instacart.library.truetime.SntpClient.doubleMillis(SntpClient.java:10)
at com.instacart.library.truetime.SntpClient.requestTime(SntpClient.java:116)
at com.instacart.library.truetime.TrueTime.requestTime(TrueTime.java:133)
at com.instacart.library.truetime.TrueTimeRx$4$1$2.subscribe(TrueTimeRx.java:211)
at io.reactivex.internal.operators.flowable.FlowableCreate.subscribeActual(FlowableCreate.java:71)
at io.reactivex.Flowable.subscribe(Flowable.java:14805)
at io.reactivex.Flowable.subscribe(Flowable.java:14752)
at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
We've been experiencing this too. Any suggestions?
Us too. Any advice would be much appreciated.
Same
Based on stacktrace and TrueTimeRx source code it looks like Flowable created for a flatmap tries to emit onNext
after chain was disposed. If that's the case you could try "sweeping it under the rug" by using RxJavaPlugins.onError
Ref. https://github.com/ReactiveX/RxJava/issues/4880
I believe I've found the issue. Inside SntpClient.java
and TrueTime.java
there are methods requestTime() throws IOException
which are responsible for whole connection magic. In the one from SntpClient.java
you can see:
catch (Exception e) {
TrueLog.d(TAG, "---- SNTP request failed for " + ntpHost);
throw e;
}
After checking Android docs it turns out that ErrnoException
doesn't extends IOException
and that is causing the crashes because TrueTimeRx
wraps call to requestTime()
and only expects to catch IOExpcetions
. Any other exception is pushed forward to RxJavaPlugins.onError()
to be handled which by default crashes as of RxJava2.
I think changing requestTime() throws IOException
to requestTime() throws Exception
( or even Throwable) should solve issue. I'd try to submit PR with this shortly.
I'm not sure the requestTime()
is capable of throwing ErrnoExceptions - requestTime()
is calling socket.send()
, which only throws IOException
s. Sockets already catch ErrnoException
and rethrow as IOException
.
I'm afraid you are right @sixpi :( Will take a look at it once again if I found some free time. All help would be appreciated. So if you have some information don't hesitate to share
Any update on this ?