truetime-android icon indicating copy to clipboard operation
truetime-android copied to clipboard

android.system.ErrnoException on SntpClient

Open cesarnorena opened this issue 5 years ago • 8 comments

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)

cesarnorena avatar Jun 03 '19 20:06 cesarnorena

We've been experiencing this too. Any suggestions?

dradding avatar Jun 14 '19 19:06 dradding

Us too. Any advice would be much appreciated.

calhouncole avatar Jun 15 '19 00:06 calhouncole

Same

guyromb avatar Jun 20 '19 09:06 guyromb

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

LosDanieloss avatar Jul 08 '19 13:07 LosDanieloss

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.

LosDanieloss avatar Jul 10 '19 12:07 LosDanieloss

I'm not sure the requestTime() is capable of throwing ErrnoExceptions - requestTime() is calling socket.send(), which only throws IOExceptions. Sockets already catch ErrnoException and rethrow as IOException.

sixpi avatar Jul 18 '19 19:07 sixpi

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

LosDanieloss avatar Jul 23 '19 08:07 LosDanieloss

Any update on this ?

radvansky-tomas avatar Feb 04 '21 20:02 radvansky-tomas