Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EC2MetadataClient.readResource() fail fast in when outside of EC2 #450

Open
eddgrant opened this issue Jun 19, 2015 · 2 comments
Open
Labels
feature-request A feature should be added or improved. help wanted We are asking the community to submit a PR to resolve this issue.

Comments

@eddgrant
Copy link

Scenario

readResource() makes use of HttpURLConnection to get metadata. When running this code outside of an EC2 instance the connection rightly fails due to the unavailability of http://169.254.169.254/latest/meta-data/instance-id outside of EC2.

The exception raised in this case is a java.net.SocketException: Connection reset. As far as I can tell from my testing the time taken to raise this exception is dependent upon the configuration of the outbound 'point-of-egress' network infrastructure. For example I discovered that whilst tethered through my phone I consistently get much quicker connection resets than whilst connected to our corporate infrastructure, which take several minutes to issue the reset packets. Incidentally I did try to configure the HttpURLConnection instance whilst in a debugger, setting connection.setConnectTimeout(5L) however this seems to have no effect.

Problem

I'm raising this as an issue because it is frustrating to have to wait for several minutes each time I want to test code locally outside of EC2. My particular use case is that I'm using Spring's Cloud AWS framework and this issue causes the Spring container to pause for several minutes upon startup when running locally. I have investigated whether it's possible only to initialise the EC2MetadataClient however this doesn't seem to be the case.

Would it be possible to introduce some sort of "am I in EC2 check" which fails fast prior to trying to obtain the meta-data? This would really ease the development cycle frustrations here.

Hope this makes sense, happy to provide more information if needed.

Many thanks!

@eddgrant eddgrant changed the title Make EC2MetadataClient fail deterministically fast in readResource() Make EC2MetadataClient fail fast in readResource() when outside of EC2 Jun 19, 2015
@eddgrant eddgrant changed the title Make EC2MetadataClient fail fast in readResource() when outside of EC2 Make EC2MetadataClient.readResource() fail fast in when outside of EC2 Jun 19, 2015
@david-at-aws david-at-aws added the feature-request A feature should be added or improved. label Aug 3, 2015
@david-at-aws
Copy link
Contributor

I'm not sure there's a great way to tell if we're on EC2 other than checking if the instance metadata service responds, but definitely worth looking into.

@debora-ito
Copy link
Member

This is just a quick update letting you know that the SDK team has reviewed the feature request list for V1 and this one looks like a great candidate for a community PR, which we’ll help merge in and support.

@debora-ito debora-ito added help wanted We are asking the community to submit a PR to resolve this issue. and removed needs-contributors labels Feb 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. help wanted We are asking the community to submit a PR to resolve this issue.
Projects
None yet
Development

No branches or pull requests

3 participants