rethink-app icon indicating copy to clipboard operation
rethink-app copied to clipboard

Crash when checking for blocklist updates when no Internet connection is available

Open afontenot opened this issue 3 years ago • 6 comments

This can happen e.g. in airplane mode (for testing) or when the connection unexpectedly fails or times out (I was able to reproduce this by testing it while rebooting my router).

Repro:

  1. Default settings + DNS-only mode + Cloudflare DoH
  2. Download the on-device blocklists and enable a few of them.
  3. Put the device in airplane mode (WiFi and cell data disabled)
  4. Click "check for update" in the blocklist dropdown.

Result: RethinkDNS crashes. After doing this multiple times Android shows the "RethinkDNS keeps crashing" warning.

Device Info: Moto X4 with LineageOS 19.1 (Android 12)


I discovered this crash while trying to reproduce a different crash (or something that seems to be a crash). Once or twice a day RethinkDNS will randomly stop working. The VPN icon will (usually) disappear from the Android taskbar at the top. When opening the app, it will be disconnected (or sometimes "failed") but then reconnect. Either something is causing the app to crash, or Android is killing it. It seemed worse when I was on a flaky cell connection, so I got the idea it could happen when a request made by the app unexpectedly failed. Any ideas about how to reproduce and isolate the problem would be appreciated.

afontenot avatar Sep 22 '22 00:09 afontenot

Any ideas about how to reproduce and isolate the problem would be appreciated.

If the app wasn't killed by battery optimizer / OOM killer, there should be a detailed log in the logcat output. But logcat has a limited per-app buffer (I believe 256K?), so, android may have captured the crash in the bugreport folder, which you can access either via (root) adb shell; cd /bugreports/ or (non-root) adb bugreport.

~~What ROM are you on?~~ On MIUI, I've seen users report crashes. On close-to-AOSP Android phones (like Pixel, OnePlus, Motorola, Asus), there are no crashes at all. The app runs for days on end just fine. Edit: Not sure why LineageOS is killing the app (or app keeps crashing on it); this is a cause of concern.

ignoramous avatar Sep 22 '22 17:09 ignoramous

Result: RethinkDNS crashes. After doing this multiple times Android shows the "RethinkDNS keeps crashing" warning.

Thanks for the steps. I have a device unfit for testing this scenario. @hussainmohd-a will test and report back.

ignoramous avatar Sep 22 '22 17:09 ignoramous

Thanks for the advice. Here's a partial logcat capturing the crash for this bug report (crash on blocklist update).

com.celzero.bravedns.logcat.txt

I haven't looked at the code closely, but it seems like I might be right that the app can crash if a connection to a DoH server unexpectedly fails. If so, this might explain some other crashes as well!

afontenot avatar Sep 22 '22 21:09 afontenot

Looks like this is the problem:

https://github.com/celzero/rethink-app/blob/0e2339d/app/src/main/java/com/celzero/bravedns/download/AppDownloadManager.kt#L95

results in cycling through every built-in DoH source when there's a connection failure, so it eventually gets to the last one SYSTEM_DNS:

https://github.com/celzero/rethink-app/blob/0e2339d/app/src/main/java/com/celzero/bravedns/customdownloader/RetrofitManager.kt#L74

but this last method doesn't provide a client, which OkHttp seems to require, so that causes the crash. Maybe this diff would fix it:

diff --git a/app/src/main/java/com/celzero/bravedns/customdownloader/RetrofitManager.kt b/app/src/main/java/com/celzero/bravedns/customdownloader/RetrofitManager.kt
index 54d1288..a7d105a 100644
--- a/app/src/main/java/com/celzero/bravedns/customdownloader/RetrofitManager.kt
+++ b/app/src/main/java/com/celzero/bravedns/customdownloader/RetrofitManager.kt
@@ -72,7 +72,7 @@ class RetrofitManager {
                         InetAddress.getByName("2001:4860:4860:0:0:0:0:8844")).build()
                 }
                 OkHttpDnsType.SYSTEM_DNS -> {
-                    return DnsOverHttps.Builder().build()
+                    return DnsOverHttps.Builder().client(OkHttpClient()).build()
                 }
             }
         }

afontenot avatar Sep 22 '22 23:09 afontenot

Thanks. The SYSTEM_DNS code exists for no good reason as it does not do what it was intended for (fallback upon system dns).

In the new code, the url for doh is still not set, yeah? That should also result in an exception, per:

https://github.com/square/okhttp/blob/118bdb28ca5a45390b730abed35ad27461ff8260/okhttp-dnsoverhttps/src/main/kotlin/okhttp3/dnsoverhttps/DnsOverHttps.kt#L254

ignoramous avatar Sep 23 '22 04:09 ignoramous

Fixed the issue, will be part of the next release. The OkHttpClient requires the DNS not to be set in order to use the system DNS.


// If unset, the system-wide default DNS will be used.
customDns(dnsType)?.let { okhttpClientBuilder.dns(it) }

returning null, in case of system DNS.

OkHttpDnsType.SYSTEM_DNS -> {
    return null
}

https://github.com/celzero/rethink-app/pull/573/commits/10cb6c45e03067eafce3cc5e7fb424a22f82e1ee

hussainmohd-a avatar Sep 23 '22 06:09 hussainmohd-a

Fixed in dev, will released with v053k that's currently blocked by #572

ignoramous avatar Sep 25 '22 03:09 ignoramous