pwittchen / ReactiveNetwork

Android library listening network connection state and Internet connectivity with RxJava Observables
http://pwittchen.github.io/ReactiveNetwork/docs/RxJava2.x/
Apache License 2.0
2.53k stars 276 forks source link

Wrong port in connectivity check calls in 3.0.7 #422

Closed andrey-bolduzev closed 4 years ago

andrey-bolduzev commented 4 years ago

Describe the bug After upgrading to 3.0.7 ReactiveNetwork.observeInternetConnectivity stops working with:

E/ReactiveNetwork( 3672): Could not establish connection with WalledGardenStrategy
E/ReactiveNetwork( 3672): java.net.ConnectException: failed to connect to clients3.google.com/2607:f8b0:400b:809::200e (port 80) after 2000ms: isConnected failed: ENETUNREACH (Network is unreachable)
E/ReactiveNetwork( 3672):   at libcore.io.IoBridge.isConnected(IoBridge.java:238)
E/ReactiveNetwork( 3672):   at libcore.io.IoBridge.connectErrno(IoBridge.java:171)
E/ReactiveNetwork( 3672):   at libcore.io.IoBridge.connect(IoBridge.java:122)
E/ReactiveNetwork( 3672):   at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
E/ReactiveNetwork( 3672):   at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
E/ReactiveNetwork( 3672):   at java.net.Socket.connect(Socket.java:882)
E/ReactiveNetwork( 3672):   at com.android.okhttp.internal.Platform.connectSocket(Platform.java:174)
E/ReactiveNetwork( 3672):   at com.android.okhttp.Connection.connect(Connection.java:152)
E/ReactiveNetwork( 3672):   at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
E/ReactiveNetwork( 3672):   at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
E/ReactiveNetwork( 3672):   at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
E/ReactiveNetwork( 3672):   at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:332)
E/ReactiveNetwork( 3672):   at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:500)
E/ReactiveNetwork( 3672):   at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
E/ReactiveNetwork( 3672):   at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)
E/ReactiveNetwork( 3672):   at com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.strategy.WalledGardenInternetObservingStrategy.isConnected(WalledGardenInternetObservingStrategy.java:109)
E/ReactiveNetwork( 3672):   at com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.strategy.WalledGardenInternetObservingStrategy$1.apply(WalledGardenInternetObservingStrategy.java:66)
E/ReactiveNetwork( 3672):   at com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.strategy.WalledGardenInternetObservingStrategy$1.apply(WalledGardenInternetObservingStrategy.java:64)
E/ReactiveNetwork( 3672):   at io.reactivex.internal.operators.observable.ObservableMap$MapObserver.onNext(ObservableMap.java:57)
E/ReactiveNetwork( 3672):   at io.reactivex.internal.operators.observable.ObservableInterval$IntervalObserver.run(ObservableInterval.java:82)
E/ReactiveNetwork( 3672):   at io.reactivex.Scheduler$PeriodicDirectTask.run(Scheduler.java:532)
E/ReactiveNetwork( 3672):   at io.reactivex.Scheduler$Worker$PeriodicTask.run(Scheduler.java:479)
E/ReactiveNetwork( 3672):   at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
E/ReactiveNetwork( 3672):   at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
E/ReactiveNetwork( 3672):   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
E/ReactiveNetwork( 3672):   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
E/ReactiveNetwork( 3672):   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
E/ReactiveNetwork( 3672):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/ReactiveNetwork( 3672):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/ReactiveNetwork( 3672):   at java.lang.Thread.run(Thread.java:818)
E/ReactiveNetwork( 3672): Caused by: android.system.ErrnoException: isConnected failed: ENETUNREACH (Network is unreachable)
E/ReactiveNetwork( 3672):   at libcore.io.IoBridge.isConnected(IoBridge.java:223)
E/ReactiveNetwork( 3672):   ... 29 more

To Reproduce Call ReactiveNetwork.observeInternetConnectivity.

Expected behavior true is emitted on detected network connectivity.

Smartphone (please complete the following information):

Additional context 3.0.6 works as expected with the default config and allowed cleartext.

The default config with 3.0.7 tries to reach https://clients3.google.com/generate_204 on port 80.

The following version with the manual port works as expected:

ReactiveNetwork.observeInternetConnectivity(
    InternetObservingSettings.builder().host("https://clients3.google.com/generate_204").port(443).build()
)!!
pwittchen commented 4 years ago

Thanks for reporting this problem. It should be fixed soon.

pwittchen commented 4 years ago

I tested it for port 443 and it didn't work in my case. I decided to change protocol from https into http in PR #425 because it works properly with default host. We can investigate this issue in the future in case of changing protocol back to https. I think not secure connection is not a big deal here because it's used just for "ping" - not for transmitting sensitive data.