orbot icon indicating copy to clipboard operation
orbot copied to clipboard

[BUG] 20% CPU overhead in kindness mode

Open Android-PowerUser opened this issue 1 year ago • 8 comments

As soon as the kindness mode is on, Orbox starts a process that uses about 20% of the CPU and cannot be turned off. Not even if the mode is turned off. I don't think that's intended. It helps to end the process or the app.

IMG_20240920_122745 Xiaomi POCO X3 pro

Android-PowerUser avatar Sep 20 '24 10:09 Android-PowerUser

Snowflake Proxy mode may not be getting turned off properly

n8fr8 avatar Jan 21 '25 14:01 n8fr8

Profiling memory and CPU usage confirms this:

The spike in CPU usage, is when I turn Kindness mode on. Then I turned it off. Then I took the screenshot. No downward curve to be witnessed.

Image

However, the code looks totally unsuspicious.

I debugged it, #disableSnowflakeProxy seems to be getting called without problem.

    public synchronized void disableSnowflakeProxy() {

        if (mSnowflakeProxy != null) {
            mSnowflakeProxy.stop();
            logNotice(getString(R.string.log_notice_snowflake_proxy_disabled));

            if (Prefs.showSnowflakeProxyMessage()) {
                var message = getString(R.string.log_notice_snowflake_proxy_disabled);
                new Handler(getMainLooper()).post(() -> Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show());
            }
            mSnowflakeProxy = null;
        }


    }

Actually a little too often for my tastes... I witnessed WiFi changes which didn't really happen - the device seemed connected continuously, but Snowflake Proxy was turned off and on again.

Anyway, a logic bug in Orbot itself seems out of the question.

But, IPtProxy looks good, too:

// Stop - Stop the Snowflake proxy.
func (sp *SnowflakeProxy) Stop() {
	if sp.isRunning {
		sp.proxy.Stop()
		sp.proxy.EventDispatcher.RemoveSnowflakeEventListener(sp)
		sp.isRunning = false
		sp.proxy = nil
	}
}

And the Snowflake code, just as well:

	for ; true; <-ticker.C {
		select {
		case <-sf.shutdown:
			return nil
		default:
			tokens.get()
			sessionID := genSessionID()
			sf.runSession(sessionID)
		}
	}
	return nil
}

// Stop closes all existing connections and shuts down the Snowflake.
func (sf *SnowflakeProxy) Stop() {
	close(sf.shutdown)
}

So… I'm at a loss, here.

@cohosh, sorry that I have to summon you once again… Do you have any ideas?

tladesignz avatar Jan 24 '25 13:01 tladesignz

How about this: https://github.com/guardianproject/orbot-android/issues/1241

syphyr avatar Jan 24 '25 16:01 syphyr

Hmm, I'll poke around a bit. I wonder if there is a race condition with the shutdown channel getting closed, and the proxy also waiting for a new snowflake.

cohosh avatar Jan 30 '25 18:01 cohosh

I seem to remember seeing the 20% once when I hadn't turned on the Kindness mode yet. But it usually turns on when the mode is turned on.

Android-PowerUser avatar Jan 30 '25 18:01 Android-PowerUser

@Android-PowerUser what version of orbot are you using?

cohosh avatar Jan 30 '25 18:01 cohosh

Version 17.3.2-RC-1-tor-0.4.8.12

Android-PowerUser avatar Jan 30 '25 18:01 Android-PowerUser

Seems to be related to https://github.com/guardianproject/orbot-android/issues/1091.

WofWca avatar May 22 '25 20:05 WofWca