-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
EC2Metadata Client's custom timeout ignores http.DefaultClient customizations post initialization #514
Comments
@pwaller, The points you mention are similar to ones we will need to consider in the future how the SDK should introduce custom timeout logic across services and operations for conditions like Modifying http.DefaultClient and http.DefaultTransport at runtime seems to easily run the risk of introducing data races. It is preferable to create a custom client and pass that around as needed to ensure data races are not introduced. It is a data race bug to be mutate shared client's parameters while being used to make requests concurrently. To address this in the most generic way ensuring that the client isn't modified at all. I'm taking a look at if we can take advantage of |
@jasdel, only the application itself (and not libraries) should modify the default timeout, and I would expect that any well behaved application would do so before initiating any requests to EC2. One other consideration: I have seen this timeout fail on occasion on EC2 instances. This is more annoying than if the request had waited longer and eventually succeeded. I would have rather it waited a bit longer and completed, or even that it would have retried a few times. Maybe one option is to relax the timeout once we know the metadata endpoint is accessible? That way you get both properties: reliability if the machine/metadata endpoint is slow, and the ability to give up on Role based credentials if the metadata endpoint is inaccessible. |
@pwaller Correct, originally this timeout was introduced in order to reduce the timeout delay (about 2min) when running on a non EC2 instance. It provided balance between quicker failures on non-EC2 instances. We could adjust the default timeout to something more appropriate, and the I agree this shorter timeout should be relaxed or removed once a connection was made. |
... and here I'am receiving DATA RACES :/ :D Removing everything and leaving Here is a part of example data race I've received.
@jasdel Thank you for finding this before me! |
To be honest I really don't get why set this timeout on default client. It's application decision to set it on http.DefaultClient. I also see you can pass your own httpClient through cfg.HTTPClient so I really don't see a reason why simple if cfg.HTTPClient == nil {
cfg.HTTPClient = http.DefaultClient
} isn't a better solution
Why then this library is different?:P |
Also the problem is not that other libraries writes, but that they might read http.DefaultClient while AWS library is writing (which also is happening for me). |
Wow, looks like I was referring to older version (still had older one) that was without #511 if httpClientZero(cfg.HTTPClient) {
if aws.BoolValue(cfg.EC2MetadataDisableHttpDefaultClientOverride) {
cfg.HTTPClient = http.DefaultClient
} else {
// If the http client is unmodified and this feature is not disabled
// set custom timeouts for EC2Metadata requests.
cfg.HTTPClient = &http.Client{
// use a shorter timeout than default because the metadata
// service is local if it is running, and to fail faster
// if not running on an ec2 instance.
Timeout: 5 * time.Second,
}
}
} |
... doh, nvm my previous comments, with new version, |
Thanks for the update @arvenil, That was going to be my first question is you'd sync'ed yet with the latest version. the usage of |
We've reviewed this issue and think that leaving the EC2Metadata service client mostly as it is. The best way to control the timeouts would be to set the The following statement shows how to disable the timeout all together. sess := session.New(aws.NewConfig().WithEC2MetadataDisabletimeoutOverride(true))
s3Svc := s3.New(sess) Modifying the |
Thanks @jasdel, seems reasonable to me. Did you decide against relaxing the timeout after the first successful attempt? |
We decided not to modify the timeouts for now due to the need to add locking around usage of the Config.HTTPClient. When the SDK looks at adding more comprehensive request timeout logic generically for a per-API operation level I think this will be re-evaluated since how the SDK uses timeouts will most likely change. |
* Adds HTTP based de/serialization typed error * This PR doesn't replace the old usages of Err codes for de/serialization error. * The serialization/ deserialization error types are generic, and not transport specific. This conforms with layered error design discussed.
In #504 and #511 changes were made to EC2Metadata Client's custom timeout to not disregard the any customizations to
http.DefaultTransport
, but this change now will ignore any customizations made tohttp.DefaultClient
. In addition to any customizations made after the metadata client has been initialized.From @pwaller's comment
The text was updated successfully, but these errors were encountered: