Bug 8192

Summary: python3.4.3 os.fork and os.waitpid (prelink related)
Product: [Build System, Metadata & Runtime] OE-Core Reporter: multisosnooley
Component: devtools / tool chainAssignee: Plauchu Edwin <edwin.plauchu.camacho>
Status: RESOLVED DUPLICATE QA Contact:
Severity: minor    
Priority: Medium CC: alejandro.hernandez, anibal.limon, benjamin.esquivel, bjorn.bosell, leonardo.sandoval.gonzalez, luke.smith, meta.mr.watcher, meta.watcher, richard.purdie
Version: unspecified   
Target Milestone: 2.3 M2   
Hardware: Other   
OS: x86   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)
Bug Depends on: 9131    
Bug Blocks:    
Attachments:
Description Flags
strace_log_before_glibc_upgrade
none
strace_log_after_glibc_upgrade none

Description multisosnooley 2015-08-21 08:53:40 UTC
Target platform: amd geode
oe-core from master

Layers:
meta
meta-yocto
meta-yocto-bsp
meta-cpc304 (https://github.com/pohmelie/meta-cpc304)

Distro: poky
BB version: 1.27.1

Build and run just fine. When I try to install something (that required compilation (!) with gcc) with "python3 -m pip" or "python3 setup.py install" then I get "No child processes" error. I have found the "bad" part: it is in distutils os.waitpid. So, I wrote simple script to reproduce the bug.

root@cpc304:~# cat yoba.py
import os 
pid = os.fork()
if pid: 
    print("parent")
    os.waitpid(pid, 0)
else:
    print("child")                                                                        
root@cpc304:~# python yoba.py                                                              
parent
child
root@cpc304:~# python3 --version
Python 3.4.3
root@cpc304:~# python3 yoba.py
parent
Traceback (most recent call last):
  File "yoba.py", line 8, in <module>
    os.waitpid(pid, 0)
ChildProcessError: [Errno 10] No child processes
root@cpc304:~#

And it works on python2 just fine, but fails on python3.4.3. Probably it's because some patches are 3.4.2 oriented (https://github.com/openembedded/oe-core/blob/master/meta/recipes-devtools/python/python3/python-3.3-multilib.patch for example), but version is 3.4.3.

Anyway right now I'm building absolutely same image but for x86_64 and will try it out with virtualbox.
Comment 1 multisosnooley 2015-08-21 08:56:32 UTC
Oh, code was cutted out.
http://pastebin.com/Ui0Rwmfn
http://pastebin.com/cvc3TKQV
Comment 2 multisosnooley 2015-08-21 14:16:30 UTC
Bug does not reproduced with x86_64 build with virtualbox. Also there is some strange behaviour with multiprocessing lib. Again, only on my board and not with virtualbox.
Comment 3 multisosnooley 2015-08-21 14:44:11 UTC
c code with fork works just fine http://pastebin.com/kJQemSzE
Comment 4 multisosnooley 2015-08-21 14:45:16 UTC
So, it definetly something "python-side"
Comment 5 multisosnooley 2015-08-24 13:54:46 UTC
python 3.3.3 from "fido" branch works just fine on my geode board.
Comment 6 Alejandro Hernandez 2015-09-11 18:43:23 UTC
I can confirm this isn't working, while I still don't exactly know what the problem is, I know its not related to python3 entirely, I was able to track the issue down to the Glibc upgrade from 2.21 to 2.22 on (which makes sense):

http://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=cb7368c110553dcb972480abc4a59b975677f7df

I will keep digging.
Comment 7 Alejandro Hernandez 2015-09-15 21:38:00 UTC
Created attachment 2734 [details]
strace_log_before_glibc_upgrade
Comment 8 Alejandro Hernandez 2015-09-15 21:39:58 UTC
Created attachment 2735 [details]
strace_log_after_glibc_upgrade
Comment 9 Alejandro Hernandez 2015-09-15 21:40:32 UTC
Following up on this issue; as it is shown on the attachments (trimmed strace logs before and after the upgrade) when using gilbc 2.22 the clone() syscall is never executed, hence why the waitpid() fails afterwards, I quickly skimmed through the modified patches, but didn't see anything at first sight that could be causing this behavior, so it might be something that changed upstream on glibc.
Comment 10 multisosnooley 2015-09-15 21:52:45 UTC
(In reply to comment #9)
Wow, awesome work! I have no experience with strace and such level of debugging, so I can't help, but I'm glad you can.
Comment 11 Alejandro Hernandez 2015-09-17 17:57:58 UTC
I'm still trying!, so this also seems to be x86 specific, I tested it on my local PC using Arch Linux (x86-64) with python 3.4 and glibc 2.22 and it worked!, so I also tested it on poky x86-64 and it worked just fine, ARM works fine too, which also may indicate that its something that changed upstream, since glibc implements fork in assembly and its architecture specific.
Comment 12 Alejandro Hernandez 2015-10-01 17:22:41 UTC
I tested this on Fedora 22 x86 using glibc 2.22 and python 3.4.2 and it works just fine, so I natively built python 3.4.2 on poky x86 linking to poky's glibc 2.22 and it worked fine as well, this means there's an issue with poky's Python3, either during compilation or with the patches
Comment 13 Alejandro Hernandez 2015-12-02 20:35:34 UTC
I tried building this with GCC 4.9 just to make sure it wasn't a GCC 5.* issue, I had the same result.
Comment 14 Aníbal Limón 2015-12-03 22:41:58 UTC
I tested on Jethro qemux86 python 3.4.3 and glibc 2.22 and works.

root@qemux86:~# python3.4 --version
Python 3.4.3
root@qemux86:~# cat yoba.py 
import os 
pid = os.fork()
if pid: 
    print("parent")
    os.waitpid(pid, 0)
else:
    print("child")
root@qemux86:~# python3   
python3            python3.4          python3.4m         
python3-config     python3.4-config   python3.4m-config  
root@qemux86:~# python3 yoba.py 
parent
child
Comment 15 Aníbal Limón 2015-12-03 22:55:31 UTC
hi multisosnooley,

Can you confirm that is failing on Jethro?

Regards,
Comment 16 multisosnooley 2015-12-03 22:58:55 UTC
(In reply to comment #15)
> Can you confirm that is failing on Jethro?
I will try, but this will took couple of days, since board are not with me right now.
Comment 17 multisosnooley 2015-12-07 14:15:56 UTC
I've just test jethro on my amd geode board (boot from usb stick) and simple python tests (os.fork and multiprocessing.Process) are ok. So, probably, this bug is covered by updates. I have no ability to play with python a lot (pip and libraries), since I can't install my linux build due some errors and I have no time and motivation to fix it.
But if Alejandro Hernandez still can reproduce this bug (AFAIR he can try to), then part(?) of bug is still there.
Comment 18 Alejandro Hernandez 2015-12-07 14:48:50 UTC
Its very likely, this was fixed by the updates, I will do a bisect to check what fixed it and mark this as solved afterwards
Comment 19 Alejandro Hernandez 2016-01-14 18:10:49 UTC
I just tested this on master (92cc02fe517bad0af4e493fda3331738cbcc9a26) using qemux86, and it's not working, so we're back were we started.

# python3.5 a.py 
parent
Traceback (most recent call last):
  File "a.py", line 8, in <module>
    os.waitpid(pid, 0)
ChildProcessError: [Errno 10] No child processes
Comment 20 Benjamin Esquivel 2016-02-19 22:50:40 UTC
moving it to minor since this is a very sporadic issue. Will continue working in it though.
Comment 21 Bjorn Bosell 2016-03-23 11:42:33 UTC
Hi,

We recently ran into a strange issue that seems very similar.
Yocto: 2.01 (Jethro)
Python: 3.4.3
Platform: imx6 (ARM Cortex-a9)

The issue we saw was that we couldn't start new processes using multiprocess.Process in python.


We were able to work around this issue in a very odd way.
After installing an image on our target, we used smart to remove python3, and then re-installed it using a rpm package repository built from the same tree as the original image.


After playing around with installing images/rpms we managed to narrowed the problem down to os.fork() returning something very bad.
(In fact, it turned out it returned a pointer to the fork() function from libc)

When running the two different scenarios (clean image vs re-installed python3) through gdb we could see that in the case where os.fork() fails, resolve_fork() is invoked instead of fork(). And resolve_fork() returns the pointer to the actual fork() function.

We do not know why this is yet, it is still very strange, "posixmodule.c" from the python sources calls fork(), but for some reason, from a fresh install the function invoked is resolve_fork().
Comment 22 Bjorn Bosell 2016-03-23 13:40:57 UTC
Sorry, that should be fork_resolve() rather than resolve_fork()
Comment 23 Bjorn Bosell 2016-03-29 13:42:30 UTC
Looks like this may be the same problem:
https://bugzilla.yoctoproject.org/show_bug.cgi?id=9131
Comment 24 Alejandro Hernandez 2016-06-09 15:33:10 UTC
(In reply to comment #23)
> Looks like this may be the same problem:
> https://bugzilla.yoctoproject.org/show_bug.cgi?id=9131

I can confirm this is the same problem, disabling pre-linking works , and since it is disabled as default, we shouldn't have a problem for now.
Comment 25 Alejandro Hernandez 2016-06-09 15:35:54 UTC
Changing the status to NEEDINFO, until the pre linking issue gets fixed.
Comment 26 Stephen K Jolley 2016-06-13 22:29:54 UTC
It shouldn't be moved to NEEDINFO if it is dependent on another bug.  I have assigned it to Mark.  If is is a duplicate, it should be closed as duplicate.  Also moved it to Medium since the comments show it is not a major issue.
Comment 27 Richard Purdie 2016-11-17 16:29:37 UTC
Could you retest this please? We enabled prelink for x86 again in August with updates to fix some of these issues.
Comment 28 Plauchu Edwin 2016-12-14 17:54:39 UTC
I Ran it again
Setting LD_USE_LOAD_BIAS=1 when starting

Yocto: master
Python: 3.5.2
Platform: qemux86
--------------------------------------------------

sh-4.3# export LD_USE_LOAD_BIAS=1
sh-4.3# cat yoba.py
import os 
pid = os.fork()
if pid: 
    print("parent")
    os.waitpid(pid, 0)
else:
    print("child")
sh-4.3# python3 yoba.py
parent
child
Comment 29 Plauchu Edwin 2016-12-14 17:58:23 UTC
I've forgotten to add the revision ( 14539203655913b3304bf98d2dd1f2e1fed3d7ca )
Comment 30 Plauchu Edwin 2016-12-15 16:25:26 UTC
We have set LD_USE_LOAD_BIAS with value 1 as per resolution in bug https://bugzilla.yoctoproject.org/show_bug.cgi?id=9131

*** This bug has been marked as a duplicate of bug 9131 ***