Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1753534

Summary: Too many open files in ImageMagick
Product: Red Hat Enterprise Linux 7 Reporter: Remi Collet <fedora>
Component: libpaperAssignee: Zdenek Dohnal <zdohnal>
Status: CLOSED ERRATA QA Contact: qe-baseos-daemons
Severity: medium Docs Contact:
Priority: medium    
Version: 7.7CC: omejzlik, thozza
Target Milestone: rcKeywords: EasyFix, Patch, TestCaseProvided, Triaged
Target Release: ---Flags: thozza: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libpaper-1.1.24-9.el7 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-09-29 19:19:33 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1757052, 1780577    

Description Remi Collet 2019-09-19 08:46:08 UTC
Running ImageMagick test suite using libgs 9.25 fails with lot of "Too many open files"

Notice:
- build was OK with 9.07 (in 7.6)
- build is OK with 9.26 (in 8.0)

Also reported as https://github.com/ImageMagick/ImageMagick/issues/1699

But looks like an issue in libgs.

Comment 2 Martin Osvald 🛹 2019-09-20 10:38:37 UTC
Hello,

thank you for reporting this problem!

While I cannot reproduce/hit the limit on opened files I can definitely see the file /etc/papersize being opened multiple times while running the tests:

~~~
# lsof /etc/papersize | wc -l
591
#
~~~

This appears to be a bug with libpaper:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=892490
https://github.com/ImageMagick/ImageMagick/issues/948
https://github.com/naota/libpaper/pull/1/commits/67a2005e8e7dcbd8b0872fabeb5badddfad19b21 [patch fixing this BZ]

Libpaper was fixed in Fedora 28 (libpaper-file-leak.patch), but the fix didn't get to RHEL7, the current RHEL-7.7 libpaper-1.1.24-8.el7 code showing no fix for it:

~~~
138 char* systempapername(void) {
...
143     FILE* ps;
...
225     }
226 
227     paperdef = defaultpapername();
228     paperstr = malloc((strlen(paperdef) + 1) * sizeof(char));
~~~

vs:

~~~
f28]$ cat libpaper-file-leak.patch
diff -up libpaper-1.1.24+nmu5/lib/paper.c.file-leak libpaper-1.1.24+nmu5/lib/paper.c
--- libpaper-1.1.24+nmu5/lib/paper.c.file-leak  2018-03-09 16:21:01.028345956 +0100
+++ libpaper-1.1.24+nmu5/lib/paper.c    2018-03-09 16:40:57.824279357 +0100
@@ -140,7 +140,7 @@ char* systempapername(void) {
     char* paperstr;
     char* paperenv;
     const char* paperdef;
-    FILE* ps;
+    FILE* ps = NULL;
     struct stat statbuf;
     const struct paper* pp;
     int c;
@@ -224,6 +224,9 @@ PAPERSIZEVAR, fall-back to the old behav
        }
     } 
       
+    if (ps)
+      fclose(ps);
+
     paperdef = defaultpapername();
     paperstr = malloc((strlen(paperdef) + 1) * sizeof(char));
     
f28]$
~~~


Reproducible using the below steps:

~~~
terminal1# yum install libgs libgs-devel @"Development Tools"
terminal1# git clone https://github.com/ImageMagick/ImageMagick.git
terminal1# cd ImageMagick/
terminal1# ./configure --with-gslib
terminal1# make
terminal1# make check
...
PASS: tests/validate-composite.tap 1
PASS: tests/validate-convert.tap 1


terminal2# lsof /etc/papersize | wc -l
538
terminal2#
~~~

Can be seen from strace output clearly:

~~~
# strace -qfTttvys 4096 -e trace=open,close -o strace-make-check.txt make check
# grep open\(  strace-make-check.txt | grep papersize | wc -l
2932
# grep close\(  strace-make-check.txt | grep papersize | wc -l
0
#
~~~


After applying the patch from Fedora 28, the problem goes away.

Changing BZ component from ghostscript to libpaper.

Comment 15 errata-xmlrpc 2020-09-29 19:19:33 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (libpaper bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:3859