dotcloud/docker-registry — pull request #72 by bshi (2013-09-06 02:39:44+00:00)
Title: Lazily establish S3 connections

See comments. This fixes a corner case with some AWS configurations
using S3.

I encountered the following errors when attempting to set up on AWS with IAM roles. I can't be sure, but I suspect the AWS metadata server is throttled. Starting gunicorn with 1 or 2 processes was fine, starting with 8 processes would trigger these exceptions since each worker was immediately attempting to establish a connection to S3.

```
2013-09-06 01:41:28,902 ERROR: Caught exception reading instance data
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/boto/utils.py", line 211, in retry_url
r = opener.open(req)
File "/usr/lib/python2.7/urllib2.py", line 400, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 418, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1207, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1177, in do_open
raise URLError(err)
URLError:
2013-09-06 01:41:28,904 ERROR: Unable to read instance data, giving up
2013-09-06 01:41:28 [10316] [ERROR] Exception in worker process:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 473, in spawn_worker
worker.init_process()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/ggevent.py", line 131, in init_process
super(GeventWorker, self).init_process()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 100, in init_process
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 106, in wsgi
self.callable = self.load()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 27, in load
return util.import_app(self.app_uri)
File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 353, in import_app
__import__(module)
File "/home/ubuntu/docker-registry-master/wsgi.py", line 11, in
import registry
File "/home/ubuntu/docker-registry-master/registry/__init__.py", line 5, in
from .tags import *
File "/home/ubuntu/docker-registry-master/registry/tags.py", line 14, in
store = storage.load()
File "/home/ubuntu/docker-registry-master/lib/storage/__init__.py", line 133, in load
store = S3Storage(cfg)
File "/home/ubuntu/docker-registry-master/lib/storage/s3.py", line 16, in __init__
self._s3_conn = boto.connect_s3()
File "/usr/local/lib/python2.7/dist-packages/boto/__init__.py", line 135, in connect_s3
return S3Connection(aws_access_key_id, aws_secret_access_key, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 174, in __init__
validate_certs=validate_certs)
File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 554, in __init__
host, config, self.provider, self._required_auth_capability())
File "/usr/local/lib/python2.7/dist-packages/boto/auth.py", line 728, in get_auth_handler
'Check your credentials' % (len(names), str(names)))
NoAuthHandlerFound: No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV1Handler'] Check your credentials
```