Bug 404652 - Thumbnailer crashes in GSCreator::create() while generating thumbnails
Summary: Thumbnailer crashes in GSCreator::create() while generating thumbnails
Status: REOPENED
Alias: None
Product: kio-extras
Classification: Frameworks and Libraries
Component: Thumbnails and previews (show other bugs)
Version: 20.04
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
: 406257 424704 424902 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-02-21 18:00 UTC by soundconjurer
Modified: 2021-05-31 03:49 UTC (History)
12 users (show)

See Also:
Latest Commit:
Version Fixed In: 20.03.80


Attachments
So many thumbnails processes spawn. (285.21 KB, image/png)
2019-02-21 18:00 UTC, soundconjurer
Details
Fix by changing exit() to _exit(). (953 bytes, patch)
2020-01-12 22:33 UTC, Ambroz Bizjak
Details

Note You need to log in before you can comment on or make changes to this bug.
Description soundconjurer 2019-02-21 18:00:25 UTC
Created attachment 118256 [details]
So many thumbnails processes spawn.

SUMMARY


STEPS TO REPRODUCE
1. Browse many folders with many PDFs or Pictures, things that generate thumbnails.
2. View processes.
3. Observe the numerous thumbnail.so processes.

OBSERVED RESULT
thumbnail.so processes are created to generate thumbnails, but the processes never seem to die off.


EXPECTED RESULT
The thumbnail.so processes close after they are finished.


SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Kubuntu 18.04.2 LTS
(available in About System)
KDE Plasma Version: 5.12.7
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 Patrick Silva 2019-02-23 13:35:32 UTC
I can't confirm here.
Ksysguard only shows 1 thumbnail.so process while dolphin generates thumbnails of 2142 jpg files.

Operating System: Arch Linux 
KDE Plasma Version: 5.15.1
KDE Frameworks Version: 5.55.0
Qt Version: 5.12.1
Comment 2 Maxim 2019-06-19 17:32:56 UTC
I can confirm it....I have the same issue
Because of these processes, Xorg begins to weigh more

SOFTWARE/OS VERSIONS
Operating System: KDE neon 5.16
KDE Plasma Version: 5.16.1
KDE Frameworks Version: 5.59.0
Qt Version: 5.12.3
Kernel Version: 4.18.0-21-generic
OS Type: 64-bit
Processors: 8 × Intel® Core™ i7-6700HQ CPU @ 2.60GHz
Memory: 11,4 ГиБ
Comment 3 Maxim 2019-06-20 06:48:46 UTC
It turned out that this is due to the fact that thumbnail.so cannot display a thumbnail for the djvu file.

Decision:
Install the djvulibre-bin package
Comment 4 JZA 2019-12-09 19:08:47 UTC
(In reply to Maxim from comment #3)
> It turned out that this is due to the fact that thumbnail.so cannot display
> a thumbnail for the djvu file.
> 
> Decision:
> Install the djvulibre-bin package

Has this step being confirmed to solved it. I havent seen a djvulibre package both on the regular repositories nor on the AUR database. 

I also experience the same issue without detecting any djvulibre document. So the issue goes beyond that. 

I would like to know how @Maxim came to this conclusion as I would like to perform a similar diagnostic and see if there is other 'thumbnail generation issues' for a different format. 

Regards.
Comment 5 Ambroz Bizjak 2020-01-12 22:32:32 UTC
I have been experiencing this on NixOS for some time. For me this bug also manifested itself as shutdown/restart hanging for 1.5 minutes as systemd waits for processes to terminate (then proceeds anyway).

Relevant part of "pstree -p":
├─thumbnail.so(4023)─┬─thumbnail.so(4028)
│                    ├─{thumbnail.so}(4024)
│                    └─{thumbnail.so}(4025)

The parent (4023) is just waiting for the child (4028) to terminate:
(gdb) attach 4023
...
(gdb) bt
#0  0x00007f0f81e88f82 in waitpid () from /nix/store/aag9d1y4wcddzzrpfmfp9lcmc7skd7jk-glibc-2.27/lib/libc.so.6
#1  0x00007f0f6d7abdba in GSCreator::create(QString const&, int, int, QImage&) ()
   from /run/current-system/sw/lib/qt-5.12.6/plugins/gsthumbnail.so
#2  0x00007f0f758fed4a in ThumbnailProtocol::get(QUrl const&) ()
   from /run/current-system/sw/lib/qt-5.12.6/plugins/kf5/kio/thumbnail.so
#3  0x00007f0f778b7416 in KIO::SlaveBase::dispatch(int, QByteArray const&) ()
   from /nix/store/sj97lmn8qy4b1rld3v6hw0d2fxiqiv7q-kio-5.64.0/lib/libKF5KIOCore.so.5
#4  0x00007f0f778b85d6 in KIO::SlaveBase::dispatchLoop() ()
   from /nix/store/sj97lmn8qy4b1rld3v6hw0d2fxiqiv7q-kio-5.64.0/lib/libKF5KIOCore.so.5
#5  0x00007f0f758fbf16 in kdemain () from /run/current-system/sw/lib/qt-5.12.6/plugins/kf5/kio/thumbnail.so
#6  0x0000000000409a75 in launch(int, char const*, char const*, char const*, int, char const*, bool, char const*, bool, char const*) ()
#7  0x000000000040ada8 in handle_launcher_request(int, char const*) [clone .isra.0] ()
#8  0x000000000040b673 in handle_requests(int) ()
#9  0x000000000040655f in main ()

The child (4028) is hung in exit() -> QtDbus atexit handler -> ... -> pthread_cond_wait().

(gdb) attach 4028
...
(gdb) bt
#0  0x00007f0f81ce6ee2 in pthread_cond_wait@@GLIBC_2.3.2 ()
   from /nix/store/aag9d1y4wcddzzrpfmfp9lcmc7skd7jk-glibc-2.27/lib/libpthread.so.0
#1  0x00007f0f825dafff in QWaitCondition::wait(QMutex*, QDeadlineTimer) ()
   from /nix/store/pf3d04a9mm6pidzzy3xm2imz1xlkqj7i-qtbase-5.12.6/lib/libQt5Core.so.5
#2  0x00007f0f825db0e9 in QWaitCondition::wait(QMutex*, unsigned long) ()
   from /nix/store/pf3d04a9mm6pidzzy3xm2imz1xlkqj7i-qtbase-5.12.6/lib/libQt5Core.so.5
#3  0x00007f0f825d4b4e in QThread::wait(unsigned long) ()
   from /nix/store/pf3d04a9mm6pidzzy3xm2imz1xlkqj7i-qtbase-5.12.6/lib/libQt5Core.so.5
#4  0x00007f0f838b8406 in ?? () from /nix/store/pf3d04a9mm6pidzzy3xm2imz1xlkqj7i-qtbase-5.12.6/lib/libQt5DBus.so.5
#5  0x00007f0f838b8499 in ?? () from /nix/store/pf3d04a9mm6pidzzy3xm2imz1xlkqj7i-qtbase-5.12.6/lib/libQt5DBus.so.5
#6  0x00007f0f81dff321 in __run_exit_handlers ()
   from /nix/store/aag9d1y4wcddzzrpfmfp9lcmc7skd7jk-glibc-2.27/lib/libc.so.6
#7  0x00007f0f81dff40a in exit () from /nix/store/aag9d1y4wcddzzrpfmfp9lcmc7skd7jk-glibc-2.27/lib/libc.so.6
#8  0x00007f0f6d7ab7b2 in GSCreator::create(QString const&, int, int, QImage&) ()
   from /run/current-system/sw/lib/qt-5.12.6/plugins/gsthumbnail.so
#9  0x00007f0f758fed4a in ThumbnailProtocol::get(QUrl const&) ()
   from /run/current-system/sw/lib/qt-5.12.6/plugins/kf5/kio/thumbnail.so
#10 0x00007f0f778b7416 in KIO::SlaveBase::dispatch(int, QByteArray const&) ()
   from /nix/store/sj97lmn8qy4b1rld3v6hw0d2fxiqiv7q-kio-5.64.0/lib/libKF5KIOCore.so.5
#11 0x00007f0f778b85d6 in KIO::SlaveBase::dispatchLoop() ()
   from /nix/store/sj97lmn8qy4b1rld3v6hw0d2fxiqiv7q-kio-5.64.0/lib/libKF5KIOCore.so.5
#12 0x00007f0f758fbf16 in kdemain () from /run/current-system/sw/lib/qt-5.12.6/plugins/kf5/kio/thumbnail.so
#13 0x0000000000409a75 in launch(int, char const*, char const*, char const*, int, char const*, bool, char const*, bool, char const*) ()
#14 0x000000000040ada8 in handle_launcher_request(int, char const*) [clone .isra.0] ()
#15 0x000000000040b673 in handle_requests(int) ()
#16 0x000000000040655f in main ()

My guess is that the atexit handler is waiting for another thread to signal a pthread condition variable, but that never happens because only the calling thread survives a fork().

In any case, the issue can be fixed by using _exit() instead of exit(), which does not run atexit handlers. I am attaching a patch, which fixes the bug for me.
Comment 6 Ambroz Bizjak 2020-01-12 22:33:34 UTC
Created attachment 125073 [details]
Fix by changing exit() to _exit().
Comment 7 Elvis Angelaccio 2020-01-19 20:35:33 UTC
Git commit 3e2ea6e924d0e2a2cdd9bb435b06965117d6d34c by Elvis Angelaccio, on behalf of Ambroz Bizjak.
Committed on 19/01/2020 at 20:35.
Pushed by elvisangelaccio into branch 'master'.

GSCreator: Fix hang due to calling exit() after fork()

Summary:
After fork(), exit() invokes atexit handlers, which can result in a lockup if an atexit handler uses thread synchronization facilities, since all but the current thread no longer exist. An example backtrace can be found in the linked bug report. Fix it by using _exit() instead of exit().
FIXED-IN: 20.03.80

Test Plan: I don't know the exact environment required to trigger this bug, but one precondition is to trigger generation of thumbnails via this code; maybe browsing folders with PDF files will do that. Once you see thumbnail.so processes staying around, you must have hit this bug. This patch should prevent this issue from occurring, and it did on my system.

Reviewers: #frameworks, elvisangelaccio

Reviewed By: elvisangelaccio

Subscribers: elvisangelaccio

Differential Revision: https://phabricator.kde.org/D26635

M  +3    -3    ps/gscreator.cpp

https://commits.kde.org/kdegraphics-thumbnailers/3e2ea6e924d0e2a2cdd9bb435b06965117d6d34c
Comment 8 Nate Graham 2020-04-18 15:36:05 UTC
*** Bug 406257 has been marked as a duplicate of this bug. ***
Comment 9 Aram 2020-08-01 20:37:16 UTC
I can confirm that the bug still exists on 20.04.3 openSUSE Tumbleweed.
When i mount an encrypted external HDD it starts to accumulate thumbnail.so processes in the memory and after closing Dolphin lot's of them remain in the memory running...
Comment 10 Nate Graham 2020-08-01 20:38:24 UTC
*** Bug 424902 has been marked as a duplicate of this bug. ***
Comment 11 Patrick Silva 2020-08-02 01:59:46 UTC
*** Bug 424704 has been marked as a duplicate of this bug. ***