aws/aws-sdk-js — pull request #448 by mick (2014-12-18 22:19:55+00:00)
Title: With a lot of concurrent requests to metadata service, credentials can fail

This is encountered as `CredentialsError: Missing credentials in config` because the request for IAM Role can timeout before all the requests are answered. fixes #445

The fix:
- add a locking so the metadata service isnt flooded with requests.
- add setImmediate so IO can still be processed even with a lot of request to the metadata service being generated.

This is a bit hard to add a test for. I did [add a test](https://github.com/mick/aws-sdk-js/compare/aws:master...mick:creds_lock?expand=1#diff-c5a12adba23f3b82dcb6d33d6980c069R42) for multiple concurrent requests to `loadCredentials`.

On an ec2 of the same type and size: [This test case](https://gist.github.com/willwhite/6afe2d333a002c33413f) passed with these changes, even with increasing concurrency up to 10000.

cc: @lsegal @willwhite