https://bugs.kde.org/show_bug.cgi?id=526997

            Bug ID: 526997
           Summary: Standard-thumbnailer processes (e.g.
                    ffmpegthumbnailer) are not killed when a
                    FilePreviewJob is cancelled or destroyed, so they pile
                    up and outlive the application
    Classification: Frameworks and Libraries
           Product: frameworks-kio
      Version First 6.30.0
       Reported In:
          Platform: CachyOS
                OS: Linux
            Status: REPORTED
          Severity: major
          Priority: NOR
         Component: general
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
            Blocks: 526995
  Target Milestone: ---

SUMMARY

KIO::FilePreviewJob does not terminate the external process of a standard
thumbnailer (a .thumbnailer file run through StandardThumbnailJob, e.g.
ffmpegthumbnailer for video) when the job is cancelled or destroyed. The
process keeps running until it exits on its own, also after the application
that requested the preview has quit. Every cancelled preview leaves one such
process behind.

This is the KIO half of bug 526995. There, Dolphin regenerates the preview of a
video that is still being written after every ~100 ms of quiet and cancels
preview jobs along the way. With a large .mkv being downloaded by a torrent
client this produced dozens of ffmpegthumbnailer processes under the dolphin
process, saturated CPU and disk, and froze the desktop. The Dolphin side (the
100 ms debounce regression from Dolphin 20.08) stays in bug 526995; this bug is
only about KIO not killing the process it started. It also explains what users
describe in bug 467774 and the "processes remain active after Dolphin is
closed" part of bug 523498 (different code path there, same expectation).


STEPS TO REPRODUCE

Real-world (full details in bug 526995):
1. Install ffmpegthumbnailer (it ships
/usr/share/thumbnailers/ffmpegthumbnailer.thumbnailer) and keep previews
enabled in Dolphin.
2. Download a large video (e.g. a 30-40 GB .mkv) with qBittorrent, default
settings (no .!qB suffix), with "Download in sequential order" enabled.
3. While the download runs, open the download folder in Dolphin, then leave the
folder or close Dolphin.
4. Check "ps -ef --forest": the ffmpegthumbnailer processes started for the
previews keep running, also after Dolphin has exited.

Minimal (follows directly from the code below; I have not run this variant
myself):
1. Create a .thumbnailer for a test MIME type whose Exec is a script that only
sleeps for a few minutes.
2. Open a folder with several such files in Dolphin with previews on, and
within 5 seconds leave the folder or close Dolphin.
3. The sleeping thumbnailer processes stay alive. If you wait longer than 5
seconds instead, the FilePreviewJob timeout kills them, which shows that only
the cancel/destroy path is missing.


OBSERVED RESULT

The external thumbnailer process survives the cancellation of its
FilePreviewJob and the exit of the application. Repeated cancellations
accumulate processes far beyond the thumbnail worker limit.


EXPECTED RESULT

Killing or destroying a FilePreviewJob terminates the thumbnailer process it
started.


ROOT CAUSE (KIO v6.30.0, unchanged in master)

- StandardThumbnailJob::start() creates the process without a parent:
      d->m_proc = new QProcess();
 
https://invent.kde.org/frameworks/kio/-/blob/v6.30.0/src/gui/standardthumbnailjob.cpp#L129
  Only StandardThumbnailJob::doKill() kills it:
 
https://invent.kde.org/frameworks/kio/-/blob/v6.30.0/src/gui/standardthumbnailjob.cpp#L110
- FilePreviewJob keeps the job in QPointer<KIO::StandardThumbnailJob>
m_standardThumbnailJob, created without a parent and never registered with
addSubjob():
 
https://invent.kde.org/frameworks/kio/-/blob/v6.30.0/src/gui/filepreviewjob.h#L174
 
https://invent.kde.org/frameworks/kio/-/blob/v6.30.0/src/gui/filepreviewjob.cpp#L547
- FilePreviewJob has no doKill() override, and ~FilePreviewJob() only removes
temporary files:
 
https://invent.kde.org/frameworks/kio/-/blob/v6.30.0/src/gui/filepreviewjob.cpp#L71
- The only place that kills the process is slotTimeout(), driven by the 5 s
timer started in start():
 
https://invent.kde.org/frameworks/kio/-/blob/v6.30.0/src/gui/filepreviewjob.cpp#L131
 
https://invent.kde.org/frameworks/kio/-/blob/v6.30.0/src/gui/filepreviewjob.cpp#L740
- KIO::Job::doKill() only kills registered subjobs():
  https://invent.kde.org/frameworks/kio/-/blob/v6.30.0/src/core/job.cpp#L164

So when a PreviewJob is killed (Dolphin does this in
KFileItemModelRolesUpdater::killPreviewJob() on many occasions, including its
destructor, see bug 526995), each FilePreviewJob is deleted together with its
timeout timer and the thumbnailer process it started is left running with
nobody to kill it. m_transferjob (the KIO::get on thumbnail:/ used for
thumbnail.so plugins) is not registered as a subjob either, so a cancelled
plugin-based preview presumably keeps its kioworker busy until it finishes as
well.


SUGGESTED FIX

1. Override FilePreviewJob::doKill() to kill m_standardThumbnailJob and
m_transferjob before calling KIO::Job::doKill(), and do the same in
~FilePreviewJob().
2. In StandardThumbnailJob, create the QProcess with a parent and kill it in
the destructor if it is still running; or register StandardThumbnailJob and the
transfer job as subjobs of FilePreviewJob so that the default doKill() covers
them.
3. Optionally limit the number of concurrently running standard-thumbnailer
processes globally, not only per PreviewJob.


SOFTWARE/OS VERSIONS

Operating System: CachyOS (Arch-based), kernel 7.2.9-2-cachyos
KDE Plasma Version: 6.7.5
KDE Frameworks Version: 6.30.0
Qt Version: 6.12.0
Graphics Platform: Wayland


ADDITIONAL INFORMATION

Dolphin 26.08.2, kio-extras 26.08.2, ffmpegthumbnailer 2.3.1.
Related: bug 526995 (Dolphin side of the same incident, blocked by this bug),
bug 467774, bug 523498.


Referenced Bugs:

https://bugs.kde.org/show_bug.cgi?id=526995
[Bug 526995] Previews of a video that is still being written (torrent) spawn
dozens of ffmpegthumbnailer processes and freeze CPU and disk: regression of
the 1000 ms -> 100 ms debounce in Dolphin 20.08 + orphaned thumbnailer
processes in KIO
-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to