Bug 98920 - update-desktop-database hangs with 100% cpu utilization
Summary: update-desktop-database hangs with 100% cpu utilization
Status: RESOLVED FIXED
Alias: None
Product: desktop-file-utils
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Hans Petter Jansson
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-01 06:06 UTC by camden.lindsay+freedesktop
Modified: 2016-12-04 05:00 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description camden.lindsay+freedesktop 2016-12-01 06:06:06 UTC
Hello-
A recent system update  (pacman -Suy) hung on my system.

>(1/1) Updating the desktop file MIME type cache...

A look at top shows 100% cpu on a single process
>12149 root      20   0   11.8m   2.4m 100.0  0.0   9:13.25 R update-desktop-                                                                                                               0.0m

Looking at the full command of the process

>[dylan@shoparch pkg]$ ps aux | grep 12149
>root     12149 99.9  0.0  12132  2472 pts/1    R+   19:14  10:49 /usr/bin/update-desktop-database --quiet
>dylan    12159  0.0  0.0  10756  2160 pts/3    S+   19:25   0:00 grep 12149
>[dylan@shoparch pkg]$ 


control + c during the update will stop the process:
>(1/1) Updating the desktop file MIME type cache...
>^C
>Interrupt signal received
>error: command terminated by signal 2: Interrupt
>[dylan@shoparch pkg]$ 

Anyway, at least i know the command, and can run it manually

I can see in help that it has a '--verbose' option
>  -v, --verbose         Display more information about processing and updating progress

run manually with a bunch of v's:
>[dylan@shoparch pkg]$ sudo /usr/bin/update-desktop-database -vvvvv
>Search path is now: [/usr/local/share/applications, /usr/share/applications]
>Could not create cache file in "/usr/local/share/applications": Error opening directory '/usr/local/share/applications': No such file or directory

The first path doesnt' exist, the second does exist, so the error I assume is expected:
>[dylan@shoparch pkg]$ ls -ld /usr/local/share/applications /usr/share/applications/
>ls: cannot access '/usr/local/share/applications': No such file or directory
>drwxr-xr-x 2 root root 4096 Nov 29 19:14 /usr/share/applications/
>[dylan@shoparch pkg]$ 

After reading the man page, its clear that update-desktop-database scans for files in those directories, with a suffix of .desktop.
There are a lot of files there that match that description:
>[dylan@shoparch pkg]$ ls -l /usr/share/applications/*.desktop | wc -l
>94

Maybe one is corrupt (even though man page says it will skip corrupt), or it is getting stuck on one...
>[dylan@shoparch pkg]$ sudo ls -l /proc/12273/fd
>total 0
>lrwx------ 1 root root 64 Nov 29 19:56 0 -> /dev/pts/3
>lrwx------ 1 root root 64 Nov 29 19:56 1 -> /dev/pts/3
>lrwx------ 1 root root 64 Nov 29 19:56 2 -> /dev/pts/3
>lr-x------ 1 root root 64 Nov 29 19:56 3 -> /usr/share/applications
>lr-x------ 1 root root 64 Nov 29 19:56 4 -> /usr/share/applications/gtk3-widget-factory.desktop
>[dylan@shoparch pkg]$ 

It hangs there and never continues.  If i remove that file, it hangs at the next file and never continues.

I moved the /usr/share/applications directory, and created a new on in it's place:  then the command executes successfully and creates a file as expected
>[dylan@shoparch pkg]$ sudo mv /usr/share/applications/ /home/dylan/
>[dylan@shoparch pkg]$ sudo mkdir /usr/share/applications
>[dylan@shoparch pkg]$ sudo /usr/bin/update-desktop-database -vvvvv
>Search path is now: [/usr/local/share/applications, /usr/share/applications]
>Could not create cache file in "/usr/local/share/applications": Error opening directory '/usr/local/share/applications': No such file or directory
>[dylan@shoparch pkg]$ echo $?
>0
>[dylan@shoparch pkg]$ ls -al /usr/share/applications/
>total 12
>drwxr-xr-x   2 root root 4096 Nov 29 20:06 .
>drwxr-xr-x 198 root root 4096 Nov 29 20:05 ..
>-rw-r--r--   1 root root   13 Nov 29 20:06 mimeinfo.cache
>[dylan@shoparch pkg]$ 

The first file it hangs on is as follows, and how it looks
>[dylan@shoparch pkg]$ ls -l /usr/share/applications/gtk3-widget-factory.desktop 
>-rw-r--r-- 1 root root 246 Nov 29 20:14 /usr/share/applications/gtk3-widget-factory.desktop
>[dylan@shoparch pkg]$ cat /usr/share/applications/gtk3-widget-factory.desktop 
>[Desktop Entry]
>Name=Widget Factory
>Comment=A showcase for GTK+ widgets, designed for testing themes.
>Exec=gtk3-widget-factory
>Icon=gtk3-widget-factory
>Terminal=false
>Type=Application
>StartupNotify=true
>Categories=Development;GTK;
>NoDisplay=true
>[dylan@shoparch pkg]$ 

I've tried copying just a single .desktop file into /usr/share/applications, but it hangs on any single file i put in the directory
I've also tried reinstalling desktop-file-utils, including forcing a new download by removing the cached file in  /var/cache/pacman/pkg/ and using pacman -Syy
I'm at a loss as to how to further troubleshoot.
Suggestions?
Comment 1 Hans Petter Jansson 2016-12-01 22:42:09 UTC
Thanks for the detailed report! Unfortunately, I'm unable to trigger the error here with that data.

Do you think you could make sure you have debug info (for glibc, glib2, desktop-file-utils) installed on your system, and get a gdb backtrace of the stuck process?

Something like this:

1) Trigger hang
2) Get process PID
3) Run: gdb update-desktop-database PID
4) (gdb) t a a bt
Comment 2 camden.lindsay+freedesktop 2016-12-02 05:02:55 UTC
Thank you for the response.

I will try to do this, but am running into problems.  

I'm trying to use the arch abs to build the above noted binaries with debug set.  I've gotten glibc and desktop-file-utils to build, but am having issues with glib2 erroring with 'a failure occured in check().'
 
Trying to troubleshoot that now, may end up filing a bug for it. 

============================================================================
Testsuite summary for glib 2.50.2
============================================================================
# TOTAL: 678
# PASS:  612
# SKIP:  32
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 34
Comment 3 camden.lindsay+freedesktop 2016-12-02 05:48:36 UTC
glib2 bug filed - https://bugzilla.gnome.org/show_bug.cgi?id=775502
Comment 4 Hans Petter Jansson 2016-12-02 19:47:47 UTC
There might be an issue with your system GVFS or D-Bus setup, but it's hard to tell.

You could get a useful trace even without glib debuginfo. Worth a shot if you've got the time.
Comment 5 camden.lindsay+freedesktop 2016-12-02 19:58:03 UTC
Thank you, Hans.

Not sure if gdb output is useful;  See below.


Attaching to program: /usr/bin/update-desktop-database, process 28688
Reading symbols from /usr/lib/libglib-2.0.so.0...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libc.so.6...done.
Reading symbols from /usr/lib/libpcre.so.1...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libpthread.so.0...done.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
Reading symbols from /lib64/ld-linux-x86-64.so.2...done.
0x00007fa4f9580ece in ?? () from /usr/lib/libglib-2.0.so.0
(gdb) t a a bt

Thread 1 (Thread 0x7fa4f9a4db40 (LWP 28688)):
#0  0x00007fa4f9580ece in ?? () from /usr/lib/libglib-2.0.so.0
#1  0x00007fa4f9581521 in ?? () from /usr/lib/libglib-2.0.so.0
#2  0x00007fa4f95816a1 in ?? () from /usr/lib/libglib-2.0.so.0
#3  0x00007fa4f9582052 in g_key_file_load_from_file () from /usr/lib/libglib-2.0.so.0
#4  0x000000000040292d in process_desktop_file (error=0x7ffcf5eba5a0, name=0x2141900 "gtk3-widget-factory.desktop", desktop_file=0x21418b0 "/usr/share/applications/gtk3-widget-factory.desktop")
    at update-desktop-database.c:111
#5  process_desktop_files (desktop_dir=desktop_dir@entry=0x21408e0 "/usr/share/applications", prefix=prefix@entry=0x40349c "", error=error@entry=0x7ffcf5eba650) at update-desktop-database.c:230
#6  0x0000000000401d14 in update_database (error=0x7ffcf5eba640, desktop_dir=0x21408e0 "/usr/share/applications") at update-desktop-database.c:380
#7  main (argc=<optimized out>, argv=<optimized out>) at update-desktop-database.c:477
(gdb)
Comment 6 Hans Petter Jansson 2016-12-03 00:46:24 UTC
Thanks, that trace is useful. It looks like it's stuck in a glib call (g_key_file_load_from_file()), and I can't see a way that update-desktop-database could get stuck in the surrounding code.

The most likely explanation is that something is up either with the state of your distro install, or glib.

Have you filed a bug against your distro? Package maintainers might know if this is affecting others too.
Comment 7 camden.lindsay+freedesktop 2016-12-04 05:00:59 UTC
Thank you for the hint.
I'd already posted on the arch forums, with no results.
I decided i'd reinstall glib2 (since it is what you indicated was hanging, and i couldn't rebuild due to the other issues)

Problem is resolved- there must have been something corrupt with my glib2 install. And i see during build one of my hard drives was requiring resets.

Thanks again for the info, I'm marking this as 'Resolved.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.