Bug 1309633

Summary: 'find -execdir' opens too many file descriptors [el7]
Product: Red Hat Enterprise Linux 7 Reporter: Branislav Náter <bnater>
Component: findutilsAssignee: Kamil Dudka <kdudka>
Status: CLOSED ERRATA QA Contact: Jakub Heger <jheger>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.2CC: benjaminmoody, bnater, fkrska, giomac, isenfeld, kdudka, mkyral, ovasik, sgaikwad, ssilverman
Target Milestone: rcKeywords: FastFix, Patch
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: findutils-4.5.11-6.el7 Doc Type: No Doc Update
Doc Text:
undefined
Story Points: ---
Clone Of: 1223557 Environment:
Last Closed: 2018-10-30 08:09:20 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: 1223557, 1465901, 1549617, 1549689, 1551061    

Description Branislav Náter 2016-02-18 10:54:06 UTC
Reproduced on findutils-4.5.11-5.el7

+++ This bug was initially created as a clone of Bug #1223557 +++

Description of problem:

I'm using Scientific Linux 6.6, but I am fairly sure this is an RHEL problem.  When using the '-execdir' option to find, the program apparently opens a new file descriptor every time it runs the command, and never closes it.

As a result, if you're traversing a directory tree that contains more
than $(ulimit -n) files (1024 by default), find will fail with the
message

  find: Failed to save working directory in order to run a command on `foo': Too many open files


Version-Release number of selected component (if applicable):

findutils-4.4.2-6.el6.x86_64


Steps to Reproduce:

An easy way to see what is happening is to run "find . -execdir sh -c 'ls /proc/self/fd | wc -l' ';'".


Actual results:

The number of open file descriptors increases every time the command is run.  When it reaches 1024, find aborts with an error.


Expected results:

The number of file descriptors should be constant, and the 'find' command should succeed, regardless of how many files are found.


Additional info:

This problem doesn't occur with the Debian version of find (which is the same upstream version, 4.4.2.)


--- Additional comment from Kamil Dudka on 2015-05-22 13:59:33 EDT ---

Thank you for reporting the bug.

I believe the following upstream commit will fix it:

http://git.savannah.gnu.org/cgit/findutils.git/commit/?id=183115d0

diff --git a/find/pred.c b/find/pred.c
index d6bbaea..2a89a37 100644
--- a/find/pred.c
+++ b/find/pred.c
@@ -681,14 +681,16 @@ impl_pred_exec (const char *pathname,
                       0);
        }

       /* Actually invoke the command. */
       result = execp->ctl.exec_callback(&execp->ctl,
                                        &execp->state);
     }
+  if (local)
+    free_cwd (execp->wd_for_exec);
   if (target != pathname)
     {
       assert (local);
       free (target);
     }
   return result;
 }

Comment 1 Kamil Dudka 2016-02-18 14:51:27 UTC
Good point.  This was fixed upstream in v4.5.11-41-g183115d, so it is not included in the 4.5.11 upstream release, which the el7 findutils package is based on.

Comment 5 Kamil Dudka 2017-07-27 07:06:07 UTC
*** Bug 1475645 has been marked as a duplicate of this bug. ***

Comment 6 Kamil Dudka 2018-04-03 13:58:57 UTC
*** Bug 1563265 has been marked as a duplicate of this bug. ***

Comment 13 errata-xmlrpc 2018-10-30 08:09:20 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, 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-2018:3076