Skip to content

make sure to close sockets that we open to detect cloud environment #1134

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

Merged
merged 2 commits into from
May 20, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
make sure to close sockets that we open to detect cloud environment
fixes #1133
  • Loading branch information
beniwohli committed May 20, 2021
commit 71b091057688b1c948f0b514ed640409868ccfab
6 changes: 4 additions & 2 deletions elasticapm/utils/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def aws_metadata():
try:
# This will throw an error if the metadata server isn't available,
# and will be quiet in the logs, unlike urllib3
socket.create_connection(("169.254.169.254", 80), 0.1)
with socket.create_connection(("169.254.169.254", 80), 0.1):
pass

try:
# This whole block is almost unnecessary. IMDSv1 will be supported
Expand Down Expand Up @@ -135,7 +136,8 @@ def azure_metadata():
try:
# This will throw an error if the metadata server isn't available,
# and will be quiet in the logs, unlike urllib3
socket.create_connection(("169.254.169.254", 80), 0.1)
with socket.create_connection(("169.254.169.254", 80), 0.1):
pass

# Can't use newest metadata service version, as it's not guaranteed
# to be available in all regions
Expand Down