abuse of socket.setdefaulttimeout() in util.py get_instance_metadata breaks threading #1935

ksquaredkey opened this Issue Dec 20, 2013 · 0 comments


None yet
2 participants

In utils.py, get_instance_metadata(), the socket.setdefaulttimeout() global is misused to cause timeouts in the urllib2 trying to access the metadata server. The problem is that the way it is used is not thread safe and results in setting the default timeout for all sockets created after being called in two threads to be 1.0 rather than the proper default of None. This is a problem if you try to use IAM Roles for EC2 on your connections.

If we can abandon 2.5, we can use the timeout arguments added to urlllib2 in 2.6. Alternatively, there needs to be locking added around the whole body of get_instance_metadata() to keep multiple threads out of the unsafe code and prevent the default timeout from being stomped by boto.

@ghost ghost assigned danielgtaylor Dec 27, 2013

danielgtaylor added a commit that referenced this issue Sep 2, 2014

Merge pull request #2560 from damz/pr/global-timeout
Use urllib timeout param instead of hacking socket global timeout. Fixes #2560, #1935.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment