Bugzilla will be upgraded to version 5.0. The upgrade date is tentatively scheduled for 2 December 2018, pending final testing and feedback.
Bug 1073165 - subprocess.Popen.communicate() fails with: IOError: [Errno 4] Interrupted system call
subprocess.Popen.communicate() fails with: IOError: [Errno 4] Interrupted sys...
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: python (Show other bugs)
6.5
Unspecified Unspecified
unspecified Severity unspecified
: rc
: ---
Assigned To: Robert Kuska
Branislav Náter
: EasyFix, Patch
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2014-03-05 18:26 EST by Dan Callaghan
Modified: 2016-04-18 06:17 EDT (History)
6 users (show)

See Also:
Fixed In Version: python-2.6.6-58.el6
Doc Type: Bug Fix
Doc Text:
Cause: subprocess.Popen.communicate() doesn't catch EINTR error if it is called without timeout and if there is only one PIPE (stdout or stderr) Consequence: subprocess.Popen.communicate() fails with IOError Fix: Make subprocess.Popen.communicate() handle EINTR errors if the process has only one pipe Result: subprocess.Popen.communicate() now works properly when only one pipe is used
Story Points: ---
Clone Of:
Environment:
Last Closed: 2015-07-22 02:39:40 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2015:1330 normal SHIPPED_LIVE Moderate: python security, bug fix, and enhancement update 2015-07-20 14:00:12 EDT

  None (edit)
Description Dan Callaghan 2014-03-05 18:26:25 EST
Description of problem:
Popen.communicate() raises IOError when the underlying read fails with EINTR due to a signal handler firing. It only happens when one of stdout or stderr is piped (therefore a possible workaround is to pipe both stdout and stderr and ignore the one that is not needed).

We see this intermittently in our Beaker self-test suite, where we execute lsof and read its stdout.

Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/nose/suite.py", line 208, in run
    self.setUp()
  File "/usr/lib/python2.6/site-packages/nose/suite.py", line 291, in setUp
    self.setupContext(ancestor)
  File "/usr/lib/python2.6/site-packages/nose/suite.py", line 314, in setupContext
    try_run(context, names)
  File "/usr/lib/python2.6/site-packages/nose/util.py", line 469, in try_run
    return func()
  File "/usr/lib/python2.6/site-packages/bkr/inttest/__init__.py", line 337, in setup_package
    process.start()
  File "/usr/lib/python2.6/site-packages/bkr/inttest/__init__.py", line 148, in start
    self._wait_for_listen(self.listen_port)
  File "/usr/lib/python2.6/site-packages/bkr/inttest/__init__.py", line 158, in _wait_for_listen
    if check_listen(self.listen_port):
  File "/usr/lib/python2.6/site-packages/bkr/inttest/__init__.py", line 109, in check_listen
    stdout=subprocess.PIPE).communicate()
  File "/usr/lib64/python2.6/subprocess.py", line 723, in communicate
    stdout = self.stdout.read()
IOError: [Errno 4] Interrupted system call

The upstream bug is: http://bugs.python.org/issue12493
Fixed upstream in Python 2.7: http://hg.python.org/cpython/rev/6a28ccde2f1b

Version-Release number of selected component (if applicable):
python-2.6.6-52.el6.x86_64

How reproducible:
easily

Steps to Reproduce:
The upstream test suite has a reliable reproducer, here is an example based on that:

Python 2.6.6 (r266:84292, Nov 21 2013, 10:50:32) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess, sys, signal
>>> def handler(signum, frame): pass
... 
>>> signal.signal(signal.SIGALRM, handler)
0
>>> p = subprocess.Popen('sleep 20', shell=True, stdout=subprocess.PIPE)
>>> signal.alarm(1) ; p.communicate()
0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.6/subprocess.py", line 723, in communicate
    stdout = self.stdout.read()
IOError: [Errno 4] Interrupted system call
>>> 

Actual results:
Popen.communicate() call raises IOError due to EINTR.

Expected results:
Popen.communicate() should retry after EINTR and successfully return a result.

Additional info:
Looks related to bug 1065537 (probably the upstream patch for this bug depends on that one).
Comment 2 Bohuslav "Slavek" Kabrda 2014-11-25 02:08:41 EST
devel_ack+, we can fix this with the referenced patch.
Comment 5 errata-xmlrpc 2015-07-22 02:39:40 EDT
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://rhn.redhat.com/errata/RHSA-2015-1330.html

Note You need to log in before you can comment on or make changes to this bug.