[New-bugs-announce] [issue29373] subprocess.Popen os.close(p2cread) in _execute_child can cause garbage collection of self.stdout to close a reused file descriptor

Zac Medico report at bugs.python.org
Wed Jan 25 12:21:16 EST 2017


New submission from Zac Medico:

In Popen _execute_child method, os.close(p2cread) closes a file descriptor which is referenced by self.stdout with closefd=True, created by this code:

   self.stdout = io.open(c2pread, 'rb', bufsize)

When self.stdout is finally garbage collected, it can close a file descriptor which has been reused since the os.close(p2cread) call. In the rare cases when this happens, it results in a traceback like the following:

Traceback (most recent call last):
  File "/usr/lib64/python3.4/subprocess.py", line 1418, in _execute_child
    part = _eintr_retry_call(os.read, errpipe_read, 50000)
  File "/usr/lib64/python3.4/subprocess.py", line 491, in _eintr_retry_call
    return func(*args)
OSError: [Errno 9] Bad file descriptor

I have observed this issue with python 3.4.5, and the code flaw also appears to be present in 3.5, 3.6, and 3.7. This sort of garbage collection issue has been highlighted in the first comment of http://bugs.python.org/issue16140, but there is still a remaining problem with this os.close(p2cread) call.

----------
messages: 286268
nosy: zmedico
priority: normal
severity: normal
status: open
title: subprocess.Popen os.close(p2cread) in _execute_child can cause garbage collection of self.stdout to close a reused file descriptor
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29373>
_______________________________________


More information about the New-bugs-announce mailing list