Project

General

Profile

Actions

Defect #44378

open

Ghostscript process is left running when PDF thumbnail generation times out

Added by Go MAEDA 1 day ago. Updated 1 day ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Attachments
Resolution:
Affected version:

Description

When generating a thumbnail for a PDF attachment, ImageMagick's convert spawns a Ghostscript (gs) process to render the PDF. If the generation exceeds thumbnails_generation_timeout, Redmine::Thumbnail.generate kills the convert process only:

rescue Timeout::Error
  Process.kill('KILL', pid)

The KILL signal is not delivered to the child gs process, so gs keeps running even after convert is gone. This can cause orphaned gs processes to accumulate on servers that receive PDFs that are slow to render.

Steps to reproduce:

1. Set thumbnails_generation_timeout in config/configuration.yml to a small value
2. Attach a PDF file that takes longer than the timeout to render (or replace gs with a script that sleeps)
3. Open a page that displays the attachment thumbnail
4. After the timeout, ps shows the gs process still running


Files

Actions #1

Updated by Go MAEDA 1 day ago

Attached are two patches to fix this issue.

0001-Fix-zombie-convert-process-left-behind-when-thumbnai.patch:

Fixes the zombie process problem, which affects all thumbnail generation, not only PDFs. When the timeout fires, Process.wait2 is interrupted, so the killed convert process is never waited on and remains defunct. The patch calls Process.detach after killing it, as `Redmine::Markdownizer already does.

0002-Fix-the-gs-process-surviving-when-PDF-thumbnail-gene.patch:

Fixes the main problem reported here. On POSIX platforms, convert is spawned in its own process group (:pgroup => true), and KILL is sent to the whole group using a negative pid. This also kills the gs process spawned by convert. On Windows, where this process-group handling is not available, the previous behavior is kept.

Actions

Also available in: Atom PDF