tahoe-lafs/src/allmydata
Brian Warner d27a57cb49 Avoid Popen() of executables that don't exist
The stdlib 'subprocess' module in python-2.7.4 through 2.7.7 suffers
from http://bugs.python.org/issue18851 which causes unrelated 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 (added in
git commit 8e31d66cd0). 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,
crashing the unit tests. 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.

This patch inserts a guard to make sure that os.path.isfile() is true
before allowing Popen.call() to try executing the target. This ought to
be enough to avoid the bug. It changes both iputil.py and
allmydata.__init__ (which uses Popen for calling "lsb_release"), which
are all the places where 'subprocess' is used outside of unit tests.

Other potential fixes: use the 'subprocess32' module from PyPI (which is
a bug-free backport of the Python3 stdlib subprocess module, but would
introduce a new dependency), or require python >= 2.7.8 (but this would
rule out development/deployment on the current OS-X 10.9 release, which
ships with 2.7.5, as well as other distributions like Ubuntu 14.04 LTS).

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). I'm hoping that this will tide us over until 1.11 is released, at
which point we can execute on the plan to remove iputil.py entirely by
changing the way that nodes learn their externally-facing IP address.
2014-09-12 13:01:56 -07:00
..
frontends Improve SFTP error handling and remove use of IFinishableConsumer. fixes #1525 2013-03-19 05:37:02 +00:00
immutable hush current pyflakes warnings (list comprehensions) 2014-06-23 13:54:07 -07:00
introducer Make introducer.furl unguessable. Closes #1802. 2013-03-20 22:40:33 +00:00
mutable publish.py: log roothash in base32, not binary 2014-09-02 13:32:59 -07:00
scripts tahoe cp -r now copies the top level directory with its children 2014-09-02 12:51:13 -07:00
storage hush current pyflakes warnings (list comprehensions) 2014-06-23 13:54:07 -07:00
test Avoid Popen() of executables that don't exist 2014-09-12 13:01:56 -07:00
util Avoid Popen() of executables that don't exist 2014-09-12 13:01:56 -07:00
web welcome.xhtml: explain MDMF too 2014-09-11 21:32:27 -07:00
windows Update more links from http: to https: in documentation and comments. 2012-03-13 20:26:54 +00:00
__init__.py Avoid Popen() of executables that don't exist 2014-09-12 13:01:56 -07:00
_auto_deps.py Suppress a DeprecationWarning from Twisted. 2014-09-01 21:12:53 +01:00
blacklist.py blacklist.py: add read() method too, for completeness 2011-08-24 19:19:02 -07:00
check_results.py Remove 'needs-rebalancing' and add 'count-happiness' to checker reports; repair tests. fixes #1784, #2105 2014-03-20 16:13:57 +00:00
client.py Better name for the file that causes a node to exit after a timeout when running unit tests. refs #1336 2014-08-17 15:51:19 +01:00
codec.py download: refactor handling of URI Extension Block and crypttext hash tree, simplify things 2008-12-05 08:17:54 -07:00
control.py switch UploadResults to use get_uri(), hide internal ._uri 2012-05-21 21:14:44 -07:00
debugshell.py
dirnode.py Change web-API to support t=relink instead of t=move (+ docs and tests). fixes #1732 2013-04-05 19:38:43 +01:00
hashtree.py hashtree.py: another micro-optimization, expand on a comment 2009-04-03 21:35:27 -07:00
history.py stop making History be a Service, it wasn't necessary 2009-08-15 04:44:15 -07:00
interfaces.py Remove 'needs-rebalancing' and add 'count-happiness' to checker reports; repair tests. fixes #1784, #2105 2014-03-20 16:13:57 +00:00
key_generator.py isolate test_keygen data 2014-01-12 21:25:11 +00:00
manhole.py trailing-whitespace eradication, no functional changes 2007-11-01 15:22:41 -07:00
monitor.py Remove spurious 'self' arguments that should not be included in interface declarations. 2012-07-24 03:32:56 +00:00
node.py remove obsolete comment 2014-08-05 16:36:59 +00:00
nodemaker.py Add comment explaining fix to #1679. refs #1679 2013-02-08 19:27:57 +00:00
stats.py Slightly improve the error message when a stats.pickle file cannot be read. 2012-07-03 14:45:22 +00:00
storage_client.py Correct off-by-one in maximum-immutable-share-size for old servers. fixes #1781 2013-03-23 03:10:50 +00:00
unknown.py Add mutable field to t=json output for unknown nodes, when mutability is known 2010-01-28 19:14:24 -08:00
uri.py src/allmydata/uri.py: Remove unused 'human encoding' methods, and associated tests. fixes #1807 2013-07-18 20:51:06 +01:00
webish.py write node.url and portnum files atomically, to fix race in test_runner 2012-05-14 15:03:14 -07:00