Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 20% CPU overhead in kindness mode #1183

Open
Android-PowerUser opened this issue Sep 20, 2024 · 7 comments
Open

[BUG] 20% CPU overhead in kindness mode #1183

Android-PowerUser opened this issue Sep 20, 2024 · 7 comments
Assignees
Labels
Milestone

Comments

@Android-PowerUser
Copy link

Android-PowerUser commented Sep 20, 2024

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

@n8fr8 n8fr8 added this to the Winter 2025 milestone Jan 21, 2025
@n8fr8
Copy link
Member

n8fr8 commented Jan 21, 2025

Snowflake Proxy mode may not be getting turned off properly

@tladesignz
Copy link
Collaborator

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?

@syphyr
Copy link
Contributor

syphyr commented Jan 24, 2025

How about this:
#1241

@cohosh
Copy link
Contributor

cohosh commented Jan 30, 2025

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.

@Android-PowerUser
Copy link
Author

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.

@cohosh
Copy link
Contributor

cohosh commented Jan 30, 2025

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

@Android-PowerUser
Copy link
Author

Version 17.3.2-RC-1-tor-0.4.8.12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants
@n8fr8 @tladesignz @syphyr @cohosh @Android-PowerUser and others