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

fix connect timeout while getting IAM creds in Docker #941

Merged
merged 4 commits into from
Jun 8, 2022

Conversation

aiudirog
Copy link
Contributor

@aiudirog aiudirog commented May 20, 2022

Description of Change

While trying to use S3FS in a Docker container on my EC2, I found that AioIMDSFetcher._fetch_metadata_token() was throwing a ConnectTimeoutError trying to connect to the metadata service with PUT http://169.254.169.254/latest/api/token/. This came from an aiohttp.ServerTimeoutError while trying to submit the PUT.

When I compared the logs to plain botocore, I found that it instead encountered a ReadTimeoutError, which it ignored and moved on to trying GET http://169.254.169.254/latest/meta-data/iam/security-credentials/, which succeeded. This error was redirected from a urllib3.ReadTimeoutError instead of a ConnectTimeoutError.

I believe this particular difference comes from aiohttp and urllib3 handling the server connection issue differently. By handling the ConnectTimeoutError, aiobotocore is able to successfully get the credentials from the metadata service while in Docker.

Note that this issue does not occur outside of Docker, even with an identical virtual env.

Assumptions

  • A ConnectTimeoutError from the metadata service shouldn't bubble up and end attempts to resolve credentials

Checklist for All Submissions

  • I have added change info to CHANGES.rst
  • If this is resolving an issue (needed so future developers can determine if change is still necessary and under what conditions) (can be provided via link to issue with these details):
    • Detailed description of issue
    • Alternative methods considered (if any)
    • How issue is being resolved
    • How issue can be reproduced
  • If this is providing a new feature (can be provided via link to issue with these details):
    • Detailed description of new feature
    • Why needed
    • Alternatives methods considered (if any)

Checklist when updating botocore and/or aiohttp versions

  • I have read and followed CONTRIBUTING.rst
  • I have updated test_patches.py where/if appropriate (also check if no changes necessary)
  • I have ensured that the awscli/boto3 versions match the updated botocore version

While trying to use S3FS in a Docker container on my EC2, I found that `AioIMDSFetcher._fetch_metadata_token()` was throwing a `ConnectTimeoutError` trying to connect to the metadata service with `PUT http://169.254.169.254/latest/api/token/`. This came from an `aiohttp.ServerTimeoutError` while trying to submit the PUT.

 When I compared the logs to plain botocore, I found that it instead encountered a `ReadTimeoutError`, which it ignored and moved on to trying `GET http://169.254.169.254/latest/meta-data/iam/security-credentials/`, which succeeded. This error was redirected from a `urllib3.ReadTimeoutError` instead of a `ConnectTimeoutError`.

 I believe this particular difference comes from aiohttp and urllib3 handling the server connection issue differently. By handling the `ConnectTimeoutError`, aiobotocore is able to successfully get the credentials from the metadata service while in Docker.

 Note that this issue does not occur outside of Docker, even with an identical virtual env.
aiobotocore/utils.py Outdated Show resolved Hide resolved
aiudirog added a commit to aiudirog/aiobotocore that referenced this pull request May 20, 2022
`aiohttp.ServerTimeoutError` should be mapped to `ReadTimeoutError`, not `ConnectTimeoutError` (aio-libs#941)
@lgtm-com
Copy link

lgtm-com bot commented May 20, 2022

This pull request introduces 1 alert when merging 215089f into a5920f6 - view on LGTM.com

new alerts:

  • 1 for Unused import

`aiohttp.ServerTimeoutError` should be mapped to `ReadTimeoutError`, not `ConnectTimeoutError` (aio-libs#941)
Comment on lines 208 to 209
except ServerTimeoutError as e:
raise ConnectTimeoutError(endpoint_url=request.url, error=e)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we still do need to support ConnectTimeoutError: https://github.com/boto/botocore/blob/develop/botocore/httpsession.py#L478. so probably need something a little more refined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Digging through the source code, it looks like we can differentiate by looking at the message:

How about:

if str(e).lower().startswith('connect'):
    raise ConnectTimeoutError(...)
else:
    raise ReadTimeoutError(...)

@aiudirog
Copy link
Contributor Author

aiudirog commented Jun 5, 2022

@thehesiod Are there any other changes you would like me to make?

@thehesiod
Copy link
Collaborator

my apologies for delay, just been crazy here

CHANGES.rst Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jun 8, 2022

Codecov Report

Merging #941 (1ef7820) into master (a5920f6) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master     #941      +/-   ##
==========================================
- Coverage   86.77%   86.74%   -0.04%     
==========================================
  Files          55       55              
  Lines        5295     5297       +2     
==========================================
  Hits         4595     4595              
- Misses        700      702       +2     
Flag Coverage Δ
unittests 86.74% <0.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiobotocore/httpsession.py 79.66% <0.00%> (-1.38%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a5920f6...1ef7820. Read the comment docs.

@thehesiod thehesiod merged commit 14f2dd1 into aio-libs:master Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants