Skip to content

Commit

Permalink
Fixes s3tools#1261 - Additional fix for CannotSendRequest at startup
Browse files Browse the repository at this point in the history
In some cases, like "timeout", and python3, despite the exception, the
connection could stay in "request-sent" state and so crash if attempting
another request.
  • Loading branch information
fviard committed Oct 3, 2022
1 parent bed73f3 commit 37909db
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions S3/Config.py
Expand Up @@ -382,8 +382,11 @@ def role_config(self):
if resp.status == 200:
imds_token = base_unicodise(resp_content)
imds_auth = {"X-aws-ec2-metadata-token": imds_token}
except:
pass
except Exception:
# Ensure to close the connection in case of timeout or
# anything. This will avoid CannotSendRequest errors for
# the next request.
conn.close()

conn.request('GET', "/latest/meta-data/iam/security-credentials/", headers=imds_auth)
resp = conn.getresponse()
Expand All @@ -408,7 +411,7 @@ def role_config(self):
raise IOError
else:
raise IOError
except:
except Exception:
raise

def role_refresh(self):
Expand Down

0 comments on commit 37909db

Please sign in to comment.