Bug 10873

Summary: bitbake leak fd's and oe-selftest fails with max_user_watches error
Product: [Build System, Metadata & Runtime] BitBake Reporter: Benjamin Esquivel <benjamin.esquivel>
Component: bitbakeAssignee: Aníbal Limón <anibal.limon>
Status: VERIFIED FIXED QA Contact: Jose Perez C <jose.perez.carranza>
Severity: normal    
Priority: High CC: anibal.limon, poky.bs.watcher, poky.watcher, richard.purdie, ross.burton
Version: 2.3   
Target Milestone: 2.3 M2   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)
Bug Depends on:    
Bug Blocks: 10826    
Attachments:
Description Flags
centos7 failure log -- exceeds fs.inotify.max_user_watches
none
debian8 fail log -- fs.inotify.max_user_watches
none
pyinotify -h
none
Execution with test_postinst_roofs_and_boot
none
Execution without test_postinst_roofs_and_boot none

Description Benjamin Esquivel 2017-01-03 16:46:44 UTC
Created attachment 3580 [details]
centos7 failure log -- exceeds fs.inotify.max_user_watches

oe-selftest --run-all-tests is unable to finish execution on most systems it is executed. It can fail with errors that indicate either there is no space or that the inode count is exceeded. Both errors are an indication of exceeding the max_user_watches given that no lack of disk space or inode count can be seen when verified.

For the following procedure to reproduce the failure, it is recommended to use the fastest machine at hand as the process takes several hours.

Procedure:

1. on the poky master branch (dbb247c), init a build environment:

  poky $ . ./oe-init-build-env

2. in order to execute oe-selftest, add the meta-selftest layer:

  build $ bitbake-layers add-layer ../meta-selftest

3. run all tests from selftest:

  build $ oe-selftest --run-all-tests

Expected Result: The test session is completed with no python exceptions.

Actual Result: The test session shows errors on disk space, inode count and/or max_user_watches. Sample failure logs attached.

Reproducibility: 100% on machines that have 8k max_user_watches (default for ubuntu, fedora, centos, debian). Hasn't been reproduced on AB Workers with 64k max_user_watches (all the main AB workers and opensuse workers of the GDC AB).
Comment 1 Benjamin Esquivel 2017-01-03 16:48:48 UTC
Created attachment 3581 [details]
debian8 fail log -- fs.inotify.max_user_watches

adding another sample fail log for debian8
Comment 2 Jose Perez C 2017-01-03 17:27:45 UTC
The TC failing is the same one in the 4 different OS where the failure is present:

- test case failing is "test_qemux86_directdisk" and is executed after  "test_qemu"

OS failing (centos7, debian8, fedora23, fedora24)

2017-01-03 01:43:30 -   test_qemu (oeqa.selftest.wic.Wic) ... OK (117.807s)
2017-01-03 01:45:27 -   test_qemux86_directdisk (oeqa.selftest.wic.Wic) ... FAIL (23.353s)
Comment 3 Benjamin Esquivel 2017-01-03 20:53:39 UTC
The workaround for this failure is to set the max_user_watches to 64k on all the workers, the same watch count that opensuse uses as default.
Comment 4 Benjamin Esquivel 2017-01-03 20:55:14 UTC
This issue has been double checked on the morty release, it is not present there. Bisecting it now.
Comment 5 Benjamin Esquivel 2017-01-03 22:43:30 UTC
the workaround has been proven correct at a debian8 machine that was failing previously.
Comment 6 Ross Burton 2017-01-04 16:52:46 UTC
I'm wondering if it would be quicker to bisect if you reduce max_user_watches to a small enough value that selftest breaks sooner if it starts leaking.

Also, why is running out of watches so fatal.  Can it be a warning? :)
Comment 7 Benjamin Esquivel 2017-01-04 20:44:04 UTC
(In reply to comment #6)
> I'm wondering if it would be quicker to bisect if you reduce
> max_user_watches to a small enough value that selftest breaks sooner if it
> starts leaking.
This test can be done manually. I'll keep it in mind.
> 
> Also, why is running out of watches so fatal.  Can it be a warning? :)
Agree, watches are overestimated.
Comment 8 Richard Purdie 2017-01-05 14:25:03 UTC
(In reply to comment #6)
> I'm wondering if it would be quicker to bisect if you reduce
> max_user_watches to a small enough value that selftest breaks sooner if it
> starts leaking.
> 
> Also, why is running out of watches so fatal.  Can it be a warning? :)

No, it can't. Memory resident bitbake needs this and I don't want multiple different ways for the cache code to work, we've enough different codepaths already. This is a place we need one codepath for everything. We did optmise it such that the overhead is minimal. We do need to figure out why they appear to be leaking though.
Comment 9 Ross Burton 2017-01-05 16:20:50 UTC
I'm pretty sure that ftrace can provide tracing on what processes are creating the inotify watches but I'm struggling to make it do what I want it to do.
Comment 10 Benjamin Esquivel 2017-01-05 17:21:07 UTC
Created attachment 3586 [details]
pyinotify -h

there is this bitbake/lib/pynotify.py that besides being the wrapper that the cooker uses, is also a command line for monitoring them. Usage attached.
Comment 11 Aníbal Limón 2017-01-05 22:42:50 UTC
Working in a RRS fix due to tinfoil API changes [1], i found an error related to BBCooker don't close all the fd's at ends of bitbake_main, see the stack trace,

Traceback (most recent call last):
  File "./rrs/rrs/tools/rrs_upgrade_history.py", line 263, in <module>
    upgrade_history(options, logger)
  File "./rrs/rrs/tools/rrs_upgrade_history.py", line 247, in upgrade_history
    do_loop(layerbranch, ct, logger)
  File "./rrs/rrs/tools/rrs_upgrade_history.py", line 185, in do_loop
    nocheckout=True)
  File "/srv/rrs/rrs/rrs/tools/common.py", line 103, in load_recipes
    logger=logger)
  File "/srv/rrs/rrs/layerindex/recipeparse.py", line 100, in init_parser
    tinfoil = _setup_tinfoil(bitbakepath, enable_tracking)
  File "/srv/rrs/rrs/layerindex/recipeparse.py", line 35, in _setup_tinfoil
    tinfoil.prepare(config_only = True)
  File "/srv/rrs/layers/bitbake/lib/bb/tinfoil.py", line 210, in prepare
    extrafeatures)
  File "/srv/rrs/layers/bitbake/lib/bb/main.py", line 513, in setup_bitbake
    server = start_server(servermodule, configParams, configuration, featureset)
  File "/srv/rrs/layers/bitbake/lib/bb/main.py", line 354, in start_server
    cooker = bb.cooker.BBCooker(configuration, features)
  File "/srv/rrs/layers/bitbake/lib/bb/cooker.py", line 178, in __init__
    self.configwatcher = pyinotify.WatchManager()
  File "/srv/rrs/layers/bitbake/lib/pyinotify.py", line 1764, in __init__
    raise OSError(err % self._inotify_wrapper.str_errno())
OSError: Cannot initialize new instance of inotify, Errno=Too many open files (EMFILE)
DEBUG: Removed the following variables from the environment: HISTSIZE, VIRTUAL_ENV, MAIL, PS1, HISTCONTROL, DJANGO_SETTINGS_MODULE, TZ, LS_COLORS, SHLVL, LANG, _, HOSTNAME, XDG_SESSION_ID, LESSOPEN, OLDPWD


This issue seems similar to this one.

[1] https://bugzilla.yoctoproject.org/show_bug.cgi?id=10863
Comment 12 Aníbal Limón 2017-01-05 23:48:17 UTC
I sent a patch to the ML, i hope it fix this error.

http://lists.openembedded.org/pipermail/bitbake-devel/2017-January/008358.html
Comment 13 Jose Perez C 2017-01-06 20:08:24 UTC
Seems like the test that is making the GDC AB fail (ABs with max_user_watches=8k) is "test_postinst_roofs_and_boot" the test case is not failing itself but is showing a lot of warnings and hence making another test cases fail. I did a test with branch http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/log/?h=JosePerez/watchers_runqemu that takes out this test case and the execution was correct everything PASS. attaching log with both executions.
Comment 14 Jose Perez C 2017-01-06 20:09:32 UTC
Created attachment 3590 [details]
Execution with test_postinst_roofs_and_boot
Comment 15 Jose Perez C 2017-01-06 20:10:21 UTC
Created attachment 3591 [details]
Execution without test_postinst_roofs_and_boot
Comment 16 Aníbal Limón 2017-01-06 20:10:57 UTC
My patch was integrate [1] but i found other errors related to non close pipe's, sockets and inotify inodes, i'm working on it.

[1] http://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=e016eb10b075e280b4e78a04e47b59a173386421
Comment 17 Aníbal Limón 2017-01-06 20:12:51 UTC
Moving to bitbake component and update title.
Comment 18 Aníbal Limón 2017-01-09 16:21:57 UTC
I sent other two patches one for pipe leakage [1] and the other that fix this issue about inotify fd's [2].


[1] http://lists.openembedded.org/pipermail/bitbake-devel/2017-January/008370.html
[2] http://lists.openembedded.org/pipermail/bitbake-devel/2017-January/008371.html
Comment 19 Ross Burton 2017-01-19 15:51:50 UTC
Fixed in bitbake ae6045b84978940c365c95c33d6996359c3e299d.
Comment 20 Jose Perez C 2017-04-11 16:16:40 UTC
Bug not present on 2.3 M3 QA test cycle 

https://wiki.yoctoproject.org/wiki/WW14_-_2017-03-28_-_Full_Test_Cycle_2.3_M3_rc2#OE-Core