Firefox freezing with 100% CPU usage for 30 seconds when launching Chromium
Recently I started to observe this very confusing and annoying, not to say worrying behaviour when having Firefox open and then launching Chromium:
For around 30 seconds, Firefox' child processes would consume all available CPU resources, causing websites to stop render (already displayed page freezes, new pages show a white page with grey spinning circle) while the overall window is still responsive (menus, page scrolling, switching tabs, even internal pages like about:config or about:preferences work...). Chromium itself does not show any symptoms. Terminating Chromium again immediately, while Firefox is spinning, does not stop the behaviour any faster.
The same happens with my regular Firefox profile, a brand new, untouched Firefox profile without any add-ons etc., Firefox started in safe mode with add-ons disabled, and Firefox started in private mode. Similar for Chromium, I can launch it with my regular profile, in incognito mode or with a temporary profile, always generating the same results.
There is nothing odd happening when Chromium is running and I open Firefox.
When launching Firefox from a terminal, I sometimes get messages like these when I quit it while it is spinning (note the pipe error line mentioning some chromium ipc...):
ExceptionHandler::GenerateDump cloned child 32165
ExceptionHandler::SendContinueSignalToChild sent continue signal to child
ExceptionHandler::WaitForContinueSignal waiting for continue signal...
[Parent 26520, Gecko_IOThread] WARNING: pipe error (52): Connection reset by peer: file /build/firefox-8oo9jx/firefox-62.0+build2/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353
ExceptionHandler::GenerateDump cloned child 32274
ExceptionHandler::WaitForContinueSignal waiting for continue signal...
ExceptionHandler::SendContinueSignalToChild sent continue signal to child
Strangely I could not reproduce that behaviour in a guest account or a newly created regular (admin) account.
Some system specs (updated):
- Ubuntu 16.04 (64 bit)
- Firefox
62.0+build2-0ubuntu0.16.04.563.0+build2-0ubuntu0.16.04.2 - Chromium
69.0.3497.81-0ubuntu0.16.04.170.0.3538.77-0ubuntu0.16.04.1 -
fontconfig
2.11.94-0ubuntu1.1 - Graphics hardware: Intel SkyLake integrated graphics (i5-6200U) + Nvidia GeForce 940M
Currently I have thenvidia-410
driver installed, but switched to the Intel prime profile. How can I further troubleshoot and fix this issue?
I made a performance profile with the Gecko Profiler Extension, installed to a clean fresh Firefox profile on my regular Ubuntu account. It can be found here: https://perfht.ml/2zpTWsh - The unresponsive time frame with 100% CPU usage should roughly correspond to the highlighted area on the Content Proc timelines, from roughly 18s - 56s.
I created a Mozilla bug report for this issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1504461
Important update: Apparently my bug report was a duplicate of https://bugzilla.mozilla.org/show_bug.cgi?id=1495900, which points out fontconfig
as the culprit. Seems like starting Chromium is making a change in the font configuration somehow, which triggers a complete reload in Firefox. This fits the performance profiling report, and also aligns with how former updates to font packages have triggered the same kind of freeze.
Any ideas how I can make the three (Firefox, Chromium, fontconfig) behave nicely along each other?
TL;DR: It's an issue with fontconfig
before version 2.13. It can be fixed by upgrading the package to 2.13 or higher (though I couldn't find a suitable provider). Alternatively, examine all your fonts-related folders and config files in your home directory and test if removing any of them resolves your issue. For me, renaming ~/.fonts
did the trick.
After learning about the bug reports https://bugzilla.mozilla.org/show_bug.cgi?id=1495900 and https://bugzilla.mozilla.org/show_bug.cgi?id=1411338 it becomes rather clear that the problem must be caused by fontconfig
.
Somehow when Chromium starts, it triggers a change in the fonts database (???), which causes Firefox - if currently running - to re-scan the file system for fonts somehow, resulting in the CPU usage and temporary freeze.
Apparently updating the fontconfig
package from version 2.11 to 2.13 (the version shipped e.g. in Ubuntu 18.10) should fix the issue, but I found no easy way to get that version on 16.04, without breaking dependencies of lots of other packages I have installed.
So as the issue is limited to my user account, I examined my user's local font configuration and folders. There's quite a mess of different font-related directories to be honest, including ~/.fonts
, ~/.local/share/fonts
, ~/.local/share-font-manager
, ~/.config/font-manager
, ~/.cache/font-manager
, ~/.cache/fontconfig
and a few more config files and application-specific font stuff.
I started by removing (renaming) the ~/.fonts
folder, as it didn't seem to contain anything useful anyway, and a simple touch ~/.fonts/Library/
before that triggered the Firefox misbehaviour. After that folder was gone, so was the issue when launching Chromium. \o/
Background
It has been proposed this Firefox Bug 1492360: High CPU usage when open Firefox before chrome/chromium. That is a duplicate of Bug 1495900: Starting Chrome makes Firefox content processes hang for about two minutes, due to FontConfig font rescanning (FcInitReinitialize), is the culprit.
But I'm on Firefox too:
And when I open up Chrome:
I don't see any performance hit to CPUs.
It may be against your morals but perhaps you can try installing google-chrome-stable
like I have. Then do the test again. If there is no CPU usage spike to 100% then a bug report could be filed between Chromium and Chrome.
I'm on Ubuntu 16.04.5 LTS. Although kernel is currently 4.14.78
LTS chain I don't think that has anything to do with it as I didn't notice CPU hits on previous kernels either.
The only time I see all CPU's at 100% is during update-initramfs
.
fontconfig
version
In the bug report it is revealed:
$ dpkg -l 'fontconfig*' | grep "^ii"
ii fontconfig 2.12.6-0ubuntu2 amd64 generic font configuration library - support binaries
ii fontconfig-config 2.12.6-0ubuntu2 all generic font configuration library - configuration
In my non-buggy version (could be because of no local fonts though):
$ dpkg -l 'fontconfig*' | grep "^ii"
ii fontconfig 2.11.94-0ubuntu1.1 amd64 generic font configuration library - support binaries
ii fontconfig-config 2.11.94-0ubuntu1.1 all generic font configuration library - configuration
I'm at 2.11.94
version earlier than bug report 2.12
version. In bug report upgrading to 2.13
is a recommended solution but OP mentioned in comments this isn't possible. As such 2.11.94
might be an option.
Judging from the log, it looks like Firefox is using synchronous IPC (Inter-process communication) for some reason. There are flags in Firefox to turn on synchronous IPC explicitly (eg: network.cookie.ipc.sync). One of those might be enabled. You can access these from the about:config page
The delay would then be a result of firefox waiting on the response. Since there is no load when Chromium has finished starting up or is not actively running, there is an immediate response.
Related: https://bugzilla.mozilla.org/show_bug.cgi?id=1331680
On Ubuntu 16.04, deleting the empty folder ~/.local/share/fonts
solved it in my case.
Quickest solution
TL;DR? Just cut and paste this command into the terminal:
echo 'user_pref("security.sandbox.content.read_path_whitelist", "/var/cache/fontconfig/,'$HOME'/.cache/fontconfig/");' >> ~/.mozilla/firefox/*.default/user.js
and restart Firefox.
Details
The problem of Firefox freezing when fonts are updated (which was the actual problem, not Chromium), is fixed by telling Firefox to not sandbox access to your font cache directory.
There was a patch for this that supposedly fixed the issue in Firefox 76. However, I'm using Firefox 78.10.0esr and the problem still occurs.
Note that while version 2.13 of fontconfig is much better than earlier versions, this slow down can still be quite painful for users with many fonts installed in $HOME/.local/share/fonts. On my machine which has fontconfig 2.13.1, Firefox had 15 seconds of 100% CPU jank every time I used touch
or rm
in the fonts directory.
The fix
Edit the file ~/.mozilla/firefox/RANDOM
.default/user.js, which may not exist, and add the following javascript:
user_pref("security.sandbox.content.read_path_whitelist",
"/var/cache/fontconfig/,/home/YOURNAME/.cache/fontconfig/");
Note 1: for inscrutable reasons, Mozilla has decided to add RANDOM letters and numbers the name of the default preferences directory. Most people only have one profile and can use *.default
to work around that silliness.
Note 2: Replace YOURNAME
with your username.