<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>13311</bug_id>
          
          <creation_ts>2019-04-30 10:25:44 +0000</creation_ts>
          <short_desc>xargs: fdleak.c:396: complain_about_leaky_fds: Assertion `no_leaks&apos; failed.</short_desc>
          <delta_ts>2023-03-07 13:42:37 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>6</classification_id>
          <classification>Yocto Project Subprojects</classification>
          <product>Pseudo</product>
          <component>pseudo</component>
          <version>2.6.1</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>4.2 M4</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Pavel Modilaynen">pavel.modilaynen</reporter>
          <assigned_to name="Yoann Congal">yoann.congal</assigned_to>
          <cc>randy.macleod</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>ross.burton</cc>
    
    <cc>seebs</cc>
    
    <cc>yoann.congal</cc>
    
    <cc>yp.pseudo.watcher</cc>
    
    <cc>yp.watcher</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>83669</commentid>
    <comment_count>0</comment_count>
      <attachid>4510</attachid>
    <who name="Pavel Modilaynen">pavel.modilaynen</who>
    <bug_when>2019-04-30 10:25:44 +0000</bug_when>
    <thetext>Created attachment 4510
patch that fixes fd leak

Any package build fails with
-------------
The stack trace of python calls that resulted in this exception/failure was:
File: &apos;exec_python_func() autogenerated&apos;, lineno: 2, function: &lt;module&gt;
     0001:
 *** 0002:extend_recipe_sysroot(d)
     0003:
File: &apos;DDD/meta/classes/staging.bbclass&apos;, lineno: 559, function: extend_recipe_sysroot
     0555:    bb.note(&quot;Installed into sysroot: %s&quot; % str(msg_adding))
     0556:    bb.note(&quot;Skipping as already exists in sysroot: %s&quot; % str(msg_exists))
     0557:
     0558:    for f in fixme:
 *** 0559:        staging_processfixme(fixme[f], f, recipesysroot, recipesysrootnative, d)
     0560:
     0561:    for p in postinsts:
     0562:        subprocess.check_output(p, shell=True, stderr=subprocess.STDOUT)
     0563:
File: &apos;DDD/meta/classes/staging.bbclass&apos;, lineno: 174, function: staging_processfixme
     0170:    for fixmevar in [&apos;COMPONENTS_DIR&apos;, &apos;HOSTTOOLS_DIR&apos;, &apos;PKGDATA_DIR&apos;, &apos;PSEUDO_LOCALSTATEDIR&apos;, &apos;LOGFIFO&apos;]:
     0171:        fixme_path = d.getVar(fixmevar)
     0172:        cmd += &quot; -e &apos;s:FIXME_%s:%s:g&apos;&quot; % (fixmevar, fixme_path)
     0173:    bb.debug(2, cmd)
 *** 0174:    subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
     0175:
     0176:
     0177:def staging_populate_sysroot_dir(targetsysroot, nativesysroot, native, d):
     0178:    import glob
File: &apos;/usr/lib/python3.5/subprocess.py&apos;, lineno: 316, function: check_output
     0312:        # empty string. That is maintained here for backwards compatibility.
     0313:        kwargs[&apos;input&apos;] = &apos;&apos; if kwargs.get(&apos;universal_newlines&apos;, False) else b&apos;&apos;
     0314:
     0315:    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
 *** 0316:               **kwargs).stdout
     0317:
     0318:
     0319:class CompletedProcess(object):
     0320:    &quot;&quot;&quot;A process that has finished running.
File: &apos;/usr/lib/python3.5/subprocess.py&apos;, lineno: 398, function: run
     0394:            raise
     0395:        retcode = process.poll()
     0396:        if check and retcode:
     0397:            raise CalledProcessError(retcode, process.args,
 *** 0398:                                     output=stdout, stderr=stderr)
     0399:    return CompletedProcess(process.args, retcode, stdout, stderr)
     0400:
     0401:
     0402:def list2cmdline(seq):
Exception: subprocess.CalledProcessError: Command &apos;sed -e &apos;s:^[^/]*/:DDD/WWW/tmp/work/cortexa9hf-neon-poky-linux-gnueabi/perl/5.24.4-r0/recipe-sysroot-native/:g&apos; DDD/WWW/tmp/sysroots-components/x86_64/rpm-native/fixmepath DDD/WWW/tmp/sysroots-components/x86_64/pkgconfig-native/fixmepath DDD/WWW/tmp/sysroots-components/x86_64/elfutils-native/fixmepath DDD/WWW/tmp/sysroots-components/x86_64/dbus-native/fixmepath DDD/WWW/tmp/sysroots-components/x86_64/python3-native/fixmepath DDD/WWW/tmp/sysroots-components/x86_64/openssl-native/fixmepath DDD/WWW/tmp/sysroots-components/x86_64/nspr-native/fixmepath DDD/WWW/tmp/sysroots-components/x86_64/e2fsprogs-native/fixmepath DDD/WWW/tmp/sysroots-components/x86_64/ncurses-native/fixmepath | xargs sed -i -e &apos;s:FIXMESTAGINGDIRTARGET:DDD/WWW/tmp/work/cortexa9hf-neon-poky-linux-gnueabi/perl/5.24.4-r0/recipe-sysroot:g; s:FIXMESTAGINGDIRHOST:DDD/WWW/tmp/work/cortexa9hf-neon-poky-linux-gnueabi/perl/5.24.4-r0/recipe-sysroot-native:g&apos; -e &apos;s:FIXME_COMPONENTS_DIR:DDD/WWW/tmp/sysroots-components:g&apos; -e &apos;s:FIXME_HOSTTOOLS_DIR:DDD/WWW/tmp/hosttools:g&apos; -e &apos;s:FIXME_PSEUDO_LOCALSTATEDIR:DDD/WWW/tmp/work/cortexa9hf-neon-poky-linux-gnueabi/perl/5.24.4-r0/pseudo/:g&apos; -e &apos;s:FIXME_LOGFIFO:DDD/WWW/tmp/work/cortexa9hf-neon-poky-linux-gnueabi/perl/5.24.4-r0/temp/fifo.3940:g&apos;&apos; returned non-zero exit status 125

Subprocess output:
xargs: File descriptor 8 will leak; please report this as a bug, remembering to include a detailed description of the simplest way to reproduce this problem.
xargs: fdleak.c:396: complain_about_leaky_fds: Assertion `no_leaks&apos; failed.
xargs: sed: terminated by signal 6
-------------

when building with enabled and redirected pseudo logging:
conf/local.conf:

FAKEROOTENV_append = &quot; PSEUDO_DEBUG=7 PSEUDO_DEBUG_FILE=&lt;&gt;/pseudolog/pseudo_dbg.log&quot;

I&apos;ve tracked down this issue and found that file descriptor 8 belong to pseudo log file descriptor itself which is leaked when xargs performs exec.
So, with the attached patch I propose to add O_CLOEXEC flag to automatically close file descriptor on forking new process with fork/exec. 

NB
I set version to 2.6.1 but I am using the latest pseudo SRCREV in bbappend with 
SRCREV = &quot;3fa7c853e0bcd6fe23f7524c2a3c9e3af90901c3&quot;

thus it&apos;s applicable to master.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83673</commentid>
    <comment_count>1</comment_count>
    <who name="Pavel Modilaynen">pavel.modilaynen</who>
    <bug_when>2019-04-30 11:31:04 +0000</bug_when>
    <thetext>I found that this issue was actually reported to findutils bug tracker https://savannah.gnu.org/bugs/?47220 however considering my findings this is not related to findutils (or xargs in particular) because fd leak does occur in pseudo.

As a side note, I wanted to mention that there is environment variable GNU_FINDUTILS_FD_LEAK_CHECK that enables fd leak check for &quot;find&quot; only for some reason. I thought &quot;xargs&quot; could utilize that too and proposed https://savannah.gnu.org/patch/?9799.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83674</commentid>
    <comment_count>2</comment_count>
    <who name="Seebs">seebs</who>
    <bug_when>2019-04-30 18:24:04 +0000</bug_when>
    <thetext>Thanks, I think you&apos;re almost certainly right, and I&apos;ll try to have a look at this more closely. But yeah, I think that is an fd leak. Good catch, thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86052</commentid>
    <comment_count>3</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2020-01-16 16:16:28 +0000</bug_when>
    <thetext>Grace/Mingli please apply the patch, test and send a commit since seebs isn&apos;t getting to this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86063</commentid>
    <comment_count>4</comment_count>
    <who name="Mingli Yu">mingli.yu</who>
    <bug_when>2020-01-17 07:24:48 +0000</bug_when>
    <thetext>The findutils 4.7.0 which includes the commit https://git.savannah.gnu.org/cgit/findutils.git/commit/?id=5699fb78d44a9f5064f98459178ee8e7fa159645 fixs the issue, I will upgrade findutils to 4.7.0 then.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86064</commentid>
    <comment_count>5</comment_count>
    <who name="Pavel Modilaynen">pavel.modilaynen</who>
    <bug_when>2020-01-17 10:37:38 +0000</bug_when>
    <thetext>Sorry Mingli, but that is not the fix, fd&apos;s are still leaking, it&apos;s just not visible after the fix (if GNU_FINDUTILS_FD_LEAK_CHECK is not set).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86065</commentid>
    <comment_count>6</comment_count>
    <who name="Mingli Yu">mingli.yu</who>
    <bug_when>2020-01-19 05:16:25 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt; Sorry Mingli, but that is not the fix, fd&apos;s are still leaking, it&apos;s just not
&gt; visible after the fix (if GNU_FINDUTILS_FD_LEAK_CHECK is not set).

Have sent the patch to http://git.yoctoproject.org/cgit/cgit.cgi/pseudo/ to ask merge the fix to pseudo git repo.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86420</commentid>
    <comment_count>7</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2020-02-13 15:59:33 +0000</bug_when>
    <thetext>Any update?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88776</commentid>
    <comment_count>8</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2020-12-16 01:59:42 +0000</bug_when>
    <thetext>We shouldn&apos;t wait for 3.4 to fix this so I&apos;ve moved the target to 3.3-M3. Richard is CCed now since he has been merging commits into pseudo. Mingli, please resend.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92471</commentid>
    <comment_count>9</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2022-02-03 16:37:17 +0000</bug_when>
    <thetext>Mingli, please update the status of this bug. Is the patch in pseudo and/or oe-core?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92834</commentid>
    <comment_count>10</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2022-03-23 00:43:07 +0000</bug_when>
    <thetext>Mingli is not able to work on this defect so I&apos;ve changed it to unassigned.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95032</commentid>
    <comment_count>11</comment_count>
    <who name="Yoann Congal">yoann.congal</who>
    <bug_when>2023-02-28 23:02:46 +0000</bug_when>
    <thetext>There was a discussion here : https://lists.openembedded.org/g/openembedded-core/topic/72391928 (on the patch mail subject)

Mingli did try to send the patch again here : https://lists.openembedded.org/g/openembedded-core/message/133813

Apparently, it was not merged.

&gt; Is the patch in pseudo and/or oe-core?

No. It&apos;s not : https://git.yoctoproject.org/pseudo/tree/pseudo_util.c#n1614
  fd = open(pseudo_path, O_WRONLY | O_APPEND | O_CREAT, 0644);
=&gt; does not contains O_CLOEXEC added by the patch

I&apos;ll try to reproduce the bug and check if Pavel&apos;s patch still fixes it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95033</commentid>
    <comment_count>12</comment_count>
    <who name="Yoann Congal">yoann.congal</who>
    <bug_when>2023-02-28 23:30:54 +0000</bug_when>
    <thetext>Reproduced with :

SUMMARY = &quot;bug-13311-repro&quot;
LICENSE = &quot;CLOSED&quot;

FAKEROOTENV:append = &quot; PSEUDO_DEBUG=7 PSEUDO_DEBUG_FILE=/tmp/pseudo_dbg.log&quot;

do_install() {
    set -x
    echo test &gt; ${D}/a
    export GNU_FINDUTILS_FD_LEAK_CHECK=1
    cat ${D}/a
    find ${D} -type f -exec sed -i &quot;s/test/&amp;ed/&quot; &apos;{}&apos; \;
    cat ${D}/a
    ls -1 ${D}/* | xargs sed -i &quot;s/test/&amp;ed/&quot;
    cat ${D}/a

    rm ${D}/a
}

=&gt; do_install fails with :
| find: File descriptor 10 will leak; please report this as a bug, remembering to include a detailed description of the simplest way to reproduce this problem.
| find: fdleak.c:396: complain_about_leaky_fds: Assertion `no_leaks&apos; failed.
| find: ‘sed’ terminated by signal 6
.../...
| xargs: File descriptor 8 will leak; please report this as a bug, remembering to include a detailed description of the simplest way to reproduce this problem.
| xargs: fdleak.c:396: complain_about_leaky_fds: Assertion `no_leaks&apos; failed.
| xargs: sed: terminated by signal 6</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95034</commentid>
    <comment_count>13</comment_count>
    <who name="Yoann Congal">yoann.congal</who>
    <bug_when>2023-03-01 00:13:26 +0000</bug_when>
    <thetext>Pavel&apos;s patch still applies and fix the bug.

Sent on ML here : 
* https://lists.openembedded.org/g/openembedded-core/message/177860 (cover)
* https://lists.openembedded.org/g/openembedded-core/message/177861</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95068</commentid>
    <comment_count>14</comment_count>
    <who name="Yoann Congal">yoann.congal</who>
    <bug_when>2023-03-07 10:32:38 +0000</bug_when>
    <thetext>Status:
https://git.yoctoproject.org/pseudo/commit/?id=ec6151a2b057109b3f798f151a36690af582e166 was merged on pseudo master
... but not integrated in poky master : https://git.yoctoproject.org/poky/tree/meta/recipes-devtools/pseudo/pseudo_git.bb#n16</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95069</commentid>
    <comment_count>15</comment_count>
    <who name="Yoann Congal">yoann.congal</who>
    <bug_when>2023-03-07 10:34:12 +0000</bug_when>
    <thetext>Moving to 4.2 M4</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95075</commentid>
    <comment_count>16</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2023-03-07 13:42:37 +0000</bug_when>
    <thetext>https://git.yoctoproject.org/poky/commit/?id=9331f576897a2b444a56ee5639f555a5ecac9fe8</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>4510</attachid>
            <date>2019-04-30 10:25:44 +0000</date>
            <delta_ts>2019-04-30 10:25:44 +0000</delta_ts>
            <desc>patch that fixes fd leak</desc>
            <filename>0001-Open-file-with-O_CLOEXEC-to-avoid-fd-leak.patch</filename>
            <type>text/plain</type>
            <size>962</size>
            <attacher name="Pavel Modilaynen">pavel.modilaynen</attacher>
            
              <data encoding="base64">RnJvbSBhNWRiNzc4MTFlOTQyNTAzZTBkY2VjZTI0MDIxOTlmMGIxZDcxMzUwIE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBQYXZlbCBNb2RpbGF5bmVuIDxwYXZlbG1uQGF4aXMuY29tPgpE
YXRlOiBNb24sIDI5IEFwciAyMDE5IDE0OjI0OjQxICswMjAwClN1YmplY3Q6IFtQQVRDSF0gT3Bl
biBmaWxlIHdpdGggT19DTE9FWEVDIHRvIGF2b2lkIGZkIGxlYWsKClVzZSBjbG9zZS1vbi1leGVj
IChPX0NMT0VYRUMpIGZsYWcgd2hlbiBvcGVuIGxvZyBmaWxlIHRvCm1ha2Ugc3VyZSBpdHMgZmls
ZSBkZXNjcmlwdG9yIGlzIG5vdCBsZWFrZWQgdG8gcGFyZW50CnByb2Nlc3Mgb24gZm9yay9leGVj
LgoKQ2hhbmdlLUlkOiBJMTY1OTNkN2M5YWRlYWFkNGEzMDZmMDhjZjZlZGIxZWY2Mjg3MzAyNwot
LS0KIHBzZXVkb191dGlsLmMgfCAyICstCiAxIGZpbGUgY2hhbmdlZCwgMSBpbnNlcnRpb24oKyks
IDEgZGVsZXRpb24oLSkKCmRpZmYgLS1naXQgYS9wc2V1ZG9fdXRpbC5jIGIvcHNldWRvX3V0aWwu
YwppbmRleCBiNDY0MTdkLi43MDNhMTg1IDEwMDY0NAotLS0gYS9wc2V1ZG9fdXRpbC5jCisrKyBi
L3BzZXVkb191dGlsLmMKQEAgLTE2MDUsNyArMTYwNSw3IEBAIHBzZXVkb19sb2dmaWxlKGNoYXIg
KmZpbGVuYW1lLCBjaGFyICpkZWZuYW1lLCBpbnQgcHJlZmVyX2ZkKSB7CiAJCX0KIAkJZnJlZShm
aWxlbmFtZSk7CiAJfQkKLQlmZCA9IG9wZW4ocHNldWRvX3BhdGgsIE9fV1JPTkxZIHwgT19BUFBF
TkQgfCBPX0NSRUFULCAwNjQ0KTsKKwlmZCA9IG9wZW4ocHNldWRvX3BhdGgsIE9fV1JPTkxZIHwg
T19BUFBFTkQgfCBPX0NSRUFUIHwgT19DTE9FWEVDLCAwNjQ0KTsKIAlpZiAoZmQgPT0gLTEpIHsK
IAkJcHNldWRvX2RpYWcoImhlbHA6IGNhbid0IG9wZW4gbG9nIGZpbGUgJXM6ICVzXG4iLCBwc2V1
ZG9fcGF0aCwgc3RyZXJyb3IoZXJybm8pKTsKIAl9IGVsc2UgewotLSAKMi4xMS4wCgo=
</data>

          </attachment>
      

    </bug>

</bugzilla>