tahoe-lafs/tahoe-lafs — pull request #108 by warner (2014-09-11 00:35:17+00:00)
Title: Switch to 'subprocess32' to avoid iputil.py crashes

The stdlib 'subprocess' module in python-2.7.4 through 2.7.7 suffers
from http://bugs.python.org/issue18851 which causes most/all file
descriptors to be closed when `subprocess.call()` fails the `exec()`,
such as when the executable being invoked does not actually exist. There
appears to be some randomness involved. This was fixed in python-2.7.8.

Tahoe's iputil.py uses subprocess.call on many different "ifconfig"-type
executables, most of which don't exist on any given platform (git commit
8e31d66). This results in a lot of file-descriptor closing, which (at
least during unit tests) tends to clobber important things like Tub TCP
sockets. This seems to be the root cause behind ticket:2121, in which
normal code tries to close already-closed sockets. Since different
platforms have different ifconfigs, some platforms will experience more
failed execs than others, so this bug could easily behave differently on
linux vs freebsd, as well as working normally on python-2.7.8 or 2.7.4.

PyPI hosts the 'subprocess32' module, which is a backport of the newer
'subprocess' from python3's stdlib. In python issue 18851, Gregory P.
Smith recommends subprocess32 for all python2 users who would normally
use the stdlib version. 'subprocess32' does not suffer from the bug.

To fix 2121, I think we must either switch to subprocess32, or require
python >= 2.7.8 (which would rule out development/deployment on the
current OS-X release, which ships with 2.7.5, as well as other
distributions). Using subprocess32 seems like the easiest fix.

I believe this closes ticket:2121, and given the apparent relationship
between 2121 and 2023, I think it also closes ticket:2023 (although
since 2023 doesn't have copies of the failing log files, it's hard to
tell).