xdg-open hogging the CPU by forking itself endlessly

7

2

Whenever xdg-open encounters a file it does not have a default application associated with it forks itself. This process repeats recursively until killed. While doing this, it of course takes up all of my CPU and memory. It seems to be a rare problem since Google doesn't know much about it. It may be important to note that this happens on multiple file types.

I'm running Manjaro Linux with Awesome WM and fish as my shell, if any of that makes a difference.

user2244484

Posted 2015-12-01T19:42:38.247

Reputation: 111

1

I googled xdg-open hogs cpu, and the first hit that came up is https://forum.manjaro.org/index.php?topic=6668.0, a link to the Manjaro forum entitled Topic: CPU and RAM rockets with many xdg-open (Read 1615 times). You might take it from here.

– MariusMatutiae – 2015-12-01T19:59:05.050

Did you solve your problem? If so, please post how you solved it exactly, then accept your own answer. This will be helpful to others with your problem! – MariusMatutiae – 2015-12-02T16:49:39.753

Way ahead of you :D – user2244484 – 2015-12-02T16:51:11.083

Way to go, user224448 ;-) – MariusMatutiae – 2015-12-02T16:53:54.120

Answers

4

Check for the value of your BROWSER environment variable. In most shells this is done by echo $BROWSER. If it's set to /usr/bin/xdg-open, therein lies your problem.

When xdg-open tries to open a web address, it does it not with the default set with xdg-mime, but with the command in the BROWSER variable. And since that command is xdg-open itself, it forks off to infinity.

Emptying this variable solves the problem. For bash, it is probably set to /usr/bin/xdg-open in ~/.bashrc, with a line like BROWSER=/usr/bin/xdg-open. Delete that line and the problem is fixed.

I assume xdg-open also uses the browser as the default opening application, leading to the same CPU eating process whenever an unknown file is handled.

Also, installing perl-file-mimeinfo and a restart might help.

Thanks MariusMatutiae for providing the link that helped me answer my own question.

user2244484

Posted 2015-12-01T19:42:38.247

Reputation: 111

It's ok to accept your own questions if it helped you solve the issue. – Vlastimil Ovčáčík – 2015-12-02T17:35:33.047

A day has to pass in order for me to do that – user2244484 – 2015-12-03T17:38:42.243

0

This is caused by the following bug in xdg-mime (part of the xdg-utils package):

https://gitlab.freedesktop.org/xdg/xdg-utils/issues/131

which, if you have any *.desktop files containing spaces, may cause xdg-mime to recurse over your entire home directory or filesystem, causing it to consume much CPU and hang. The fix is committed to xdg-utils and maintainers should package it.

While you wait, you can simply add the missing pair of quotes by editing the xdg-mime script as in the pull request:

This occurs in the function search_desktop_file(), add those quotes on line 930 in xdg-utils 1.1.3, adding quotes around $dir in the following block:

    for f in "$dir"/*/; do 
      [ -d "$f" ] && search_desktop_file "$MIME" "$f" 
    done

This is the cause of many bugs for years in other apps such as Discord, which starts with a black screen and spawns a process that consumes a lot of CPU while Discord waits for it to exit:

xdg-mime query default x-scheme-handler/spotify

Maintainers, please update xdg-utils!

Bob McElrath

Posted 2015-12-01T19:42:38.247

Reputation: 141