EFForg / privacybadger

Privacy Badger is a browser extension that automatically learns to block invisible trackers.
https://privacybadger.org
Other
3.19k stars 386 forks source link

Privacy Badger on Chrome on Linux consuming high CPU #2954

Closed ghostwords closed 5 months ago

ghostwords commented 8 months ago

Discussed in https://github.com/EFForg/privacybadger/discussions/2953

How does one debug (to see if it is related to a specific tab)?

Originally posted by **nhed** March 6, 2024 Seen it happen several times (over several PB versions). Laptop fans spinning up, `htop` showing high cpu taken by chrome, chrome's task manager shows PB as highest CPU user. ![image](https://github.com/EFForg/privacybadger/assets/513759/13cd85fc-a7c1-4549-b881-4bcdc9565feb) - `uname -r`: `6.5.10-200.fc38.x86_64` - `rpm -q google-chrome-stable`: `google-chrome-stable-120.0.6099.224-1.x86_64` - PB version: `2024.2.6` Disabled & Re-enabled and things quieted down Did not see any discussion re CPU usage (is this the right place to have this convo?)
ghostwords commented 8 months ago

@nhed Are you able to reproduce this bug? For example, does this happen regularly while using Google Meet or some other specific website?

nhed commented 8 months ago

Seen it very high couple of time before in both I disabled and issue went away. Unrelated to Google Meet - I thing it started before I had to get on the call. I am unable to correlate to a specific website but I do have many tabs open (shame, i know)

Worth nothing that I run with two profile-dirs, personal and work (i think task manager shows a global view, so shows tasks from both profiles?) and at the time I had the PB extension only installed on the profile that was not running the Google Meet.

Right now when I'm not running a google meet I just saw 65% usage and non-responsive extension button.
Disabled and re-enabled extension cpu dropped but extension (button and options) is non responsive

ghostwords commented 8 months ago

Thanks for the additional information! It sounds like it's something about your particular installation of Privacy Badger. Uninstalling and reinstalling Privacy Badger may fix the problem.

If you would like to try debugging though, you could navigate to chrome://extensions, enable developer mode in the upper right corner, and then click on the "background.html" link in Privacy Badger's listing. This will open developer tools for Privacy Badger's background process.

The first thing to do once you've got developer tools open is to see if there are any meaningful errors in the Console tab.

If you can consistently reproduce excessive CPU use, you can also switch over to the Performance tab, start recording a performance profile, and while recording, perform the actions that cause your Privacy Badger to use excessive CPU. We could then review what exactly Privacy Badger did at the time of high CPU use.

Once you finish making a performance recording, you can right-click inside the Performance tab and select "Save profile" to export the performance data.

nhed commented 8 months ago

image

Seeing this also after re-installing (but see below, I should have confirmed removal from underlying filesystem and probably browser restart).

nhed commented 8 months ago

well - maybe uninstalling extension and restarting chrome would have done the trick - not sure

When I checked underlying storage to see which LOCK file was attempted - I noticed there were two - one under Local Extension Settings and one under Managed Extension Settings (is the latter because my browser is managed by my org?)

Noticed that the date on the LOCK file was old and renamed whole dir while reinstalling ext - but only then noticed with lsof that chrome was holding on to said renamed dir even when the ext was uninstalled.

after forcing restart of chrome - things came back ok (ext is now responsive)

I will now monitor for the CPU issues and come back here if it recurs

Thanks

ghostwords commented 8 months ago

Sounds good, thank you!

ghostwords commented 8 months ago

Looks like the Chrome IO lock error means that Chrome extension storage is broken, which would break pretty much all browser extensions. Restarting Chrome should fix it though. Not sure why or when this happens.

nhed commented 7 months ago

Just started seeing it again today. Seeing the same LOCK issue - not sure if there is a point in doing the performance recording but did anyway and sent while awaiting disabled the extension (I think it will recreate as long as I do not restart browser - and guarantee proper cleanup in between)

ghostwords commented 7 months ago

Thanks for the performance recording!

It looks like the CPU is maxed out because while Privacy Badger failed to properly initialize, probably because of JS errors, maybe the one above, Privacy Badger still injected "content scripts" into the page (for example to help remove tracking from some links inside Gmail) and the content scripts want to know whether they should proceed but Privacy Badger isn't ready to respond to them yet but it will never be ready because of the JS errors and we get an infinite loop at this point.

So ... I should be able to fix the infinite loop, which will fix the CPU issue. However, Privacy Badger will still break now and then for you, where it will fail to finish initializing because something is badly wrong with browser extension storage.

It would be good to figure out what to do to fix the underlying extension storage Chrome issue. Will removing your Chrome profile and starting from scratch do it? Do other people run into this problem? It doesn't seem specific to Privacy Badger.

nhed commented 7 months ago

Would your fix have any visual indications that the extension failed to initialize? Let me know if you want me to test - I intentionally left the browser going and just disabled the extention. I cloned your PR branch and I think I'm supposed to "load unpacked" while pointing to the src dir but not sure if there is some prep step to run on the local repo

ghostwords commented 7 months ago

Sure, testing would be really nice! We could also then take another look at the errors that cause Privacy Badger to fail on initialization.

There are no extra steps, no build process, just load from src/. Let me know here or over email if you have any questions, and thank you!

ghostwords commented 7 months ago

Would your fix have any visual indications that the extension failed to initialize?

No, the only the thing I changed in #2955 is that the CPU-consuming infinite loop should terminate in under ten seconds.

nhed commented 7 months ago

unfortunately since offering to test my browser did crash so it will probably be a while before I run into the lock/local-storage issues (but I have the extension loaded from source - had issue running it before the browser restart)

ghostwords commented 7 months ago

I updated #2955 to also style the badge with a red exclamation mark and to show an error message in the popup once failed initialization is detected (after ten seconds or so).