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

RethinkDNS crashes when i press "Start"

Open peter099 opened this issue 2 years ago • 4 comments

When i press the button "Start" RethinkDNS crashes. I downloaded the app from f-droid and on my phone i am using LineageOS 17.

peter099 avatar Aug 01 '22 14:08 peter099

Related experience.

RethinkDNS: v053i Device: Samsung M20g. Official ROM.

It crash when;

  • After restart and RethinkDNS was running.
  • After restart, RethinkDNS was running and other app (like pDNSf) grab VPN line 1st. I do play with some Blocker apps and occasionally forgot about autostart.
  • On random time. RethinkDNS will block network 1st, DNS fail I believe. I suspect happen when Network choked. I can't monitor it as it usually happen when device idle for long time. Pressing Stop then Start again will crash RethinkDNS.

MicroBeast avatar Aug 03 '22 18:08 MicroBeast

If I press "Stop" and then press "Start", it crashes. Then if I open the app again and press "Start" again, it works. Quite strange.

Fairphone 4. Stock Android 11.

Dyras avatar Aug 03 '22 20:08 Dyras

Would you know how to grab and share logs via adb logcat / bugreport? If so, grab 'em immediately following the crash, email it to mz @ celzero dot com

ignoramous avatar Aug 06 '22 01:08 ignoramous

Sent!

Dyras avatar Aug 06 '22 07:08 Dyras

Fixed in https://github.com/celzero/rethink-app/pull/525

Releasing in a day or two.

ignoramous avatar Sep 07 '22 05:09 ignoramous

@ignoramous Sadly, this seems to still be happening for me. Do you need another logcat? If so I can email you again.

Dyras avatar Sep 13 '22 09:09 Dyras

@ignoramous Sadly, this seems to still be happening for me. Do you need another logcat? If so I can email you again.

On v053j?

ignoramous avatar Sep 13 '22 19:09 ignoramous

@ignoramous Yes sir. The F-Droid version is what I'm using.

Dyras avatar Sep 14 '22 08:09 Dyras

So, when you tap on START, the app crashes, and right after the crash, START works, yeah?

You see this behaviour every other time you attempt to START Rethink?

Can you please email the logs you capture just after the crash happens to mz at celzero dot com?

ignoramous avatar Sep 14 '22 18:09 ignoramous

I've sent you another email! Here's a video for how to reproduce it. It happens near 10/10 times.

In the video I start, stop, start almost right after one another, but this happens even if you start, leave the app for hours, stop, leave the app for hours, start.

https://user-images.githubusercontent.com/12563436/190452872-d1876787-8f98-4b17-a814-f477d26eb478.mp4

Dyras avatar Sep 15 '22 16:09 Dyras

Same behavior here

Start = ok Stop = ok Restart = crash

^ everytime

Android 10, huawei

nahuhh avatar Sep 16 '22 22:09 nahuhh

I've sent you another email! Here's a video for how to reproduce it. It happens near 10/10 times.

Thanks. The logs say:

09-15 15:27:56.975 13508 13508 E AndroidRuntime: Process: com.celzero.bravedns, PID: 13508
09-15 15:27:56.975 13508 13508 E AndroidRuntime: android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{a90cab5 u0 com.celzero.bravedns/.service.BraveVPNService}
09-15 15:27:56.975 13508 13508 E AndroidRuntime: >--at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2006)
09-15 15:27:56.975 13508 13508 E AndroidRuntime: >--at android.os.Handler.dispatchMessage(Handler.java:106)
09-15 15:27:56.975 13508 13508 E AndroidRuntime: >--at android.os.Looper.loop(Looper.java:223)
09-15 15:27:56.975 13508 13508 E AndroidRuntime: >--at android.app.ActivityThread.main(ActivityThread.java:7715)
09-15 15:27:56.975 13508 13508 E AndroidRuntime: >--at java.lang.reflect.Method.invoke(Native Method)
09-15 15:27:56.975 13508 13508 E AndroidRuntime: >--at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
09-15 15:27:56.975 13508 13508 E AndroidRuntime: >--at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)

And just prior I see one after the other shared-preference triggers for enabled (vpn-enabled set to true), which causes the vpn to "restart" over and over again?

I think we are missing return statement after signalStopService() calls here (and possibly add Log.w too:

https://github.com/celzero/rethink-app/blob/adf8b89f65570ebce92c95e3804e61d058b86b52/app/src/main/java/com/celzero/bravedns/service/BraveVPNService.kt#L1174

https://github.com/celzero/rethink-app/blob/adf8b89f65570ebce92c95e3804e61d058b86b52/app/src/main/java/com/celzero/bravedns/service/BraveVPNService.kt#L1385

https://github.com/celzero/rethink-app/blob/adf8b89f65570ebce92c95e3804e61d058b86b52/app/src/main/java/com/celzero/bravedns/service/BraveVPNService.kt#L1402

ignoramous avatar Sep 18 '22 18:09 ignoramous

This crash is 100% reproducible if there is at least one app that's excluded from the VPN. The reason was there was race between BraveVpnService#restartVpn (invoked by excludeApps LiveData change observer init'd in BraveVpnService#onCreate) and BraveVpnService#onStartCommand (invoked by VpnController#start in response to user action) trying to do different things.

restartVpn sees persistentState#isVpnEnabled is false before onStartCommand can set it to true and so, restartVpn tries to signalStopService whereas onStartCommand is trying to start it, causing mayhem.

The fix is multi-fold:

  1. Observe interesting LiveData changes after a new Vpn is created.
  2. Set persistentState#vpnEnabled(true) before updateTun or restartVpn is invoked from onStartCommand.
  3. Call startForeground from onStartCommand as quickly as appropriate.
  4. After calling signalStopService from updateTun and restartVpn, return back to the caller, instead of proceeding as usual.

The fix will be in the next release v053j. Thanks for everyone who sent the logs and videos along!

ignoramous avatar Sep 19 '22 16:09 ignoramous

The fix will be in the next release v053j.

053j is the latest fdroid release. Do you mean v053k?

nahuhh avatar Oct 03 '22 01:10 nahuhh

Yeah, v053k ;)

ignoramous avatar Oct 03 '22 06:10 ignoramous

Yeah, v053k ;)

Can confirm fixed on fdroid v053k

nahuhh avatar Oct 17 '22 22:10 nahuhh

Crashed with v054c [F-Droid], while updating from previous version.

logs
FATAL EXCEPTION: main
Process: com.celzero.bravedns, PID: 26480
android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground()
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1771)
 at android.os.Handler.dispatchMessage(Handler.java:106)
 at android.os.Looper.loop(Looper.java:164)
 at android.app.ActivityThread.main(ActivityThread.java:6518)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

shuvashish76 avatar May 13 '23 20:05 shuvashish76

Hi @shuvashish76: I am not able to reproduce the crash. Are you seeing this 100% of the time? If so, how are you reproducing this bug?

ignoramous avatar May 13 '23 22:05 ignoramous

Are you seeing this 100% of the time?

1time crash only. Tried to reproduce the crash but no results.

shuvashish76 avatar May 14 '23 00:05 shuvashish76

Thanks. So it is unrelated to this bug (which happened 100% of the time when at least one app was excluded). I'll create a new bug if we get more reports of it to look into that code a bit more.

ignoramous avatar May 14 '23 00:05 ignoramous