Skip to content

Commit

Permalink
feat: Add retries to requests sessions
Browse files Browse the repository at this point in the history
Every so often we get connection timed out errors towards our HCP Vault
endpoint. This is usually when a larger number of jobs is running
simultaneously. Considering requests for other jobs do still succeed this
is probably load related and adding a retry should help in making this a
bit more robust.
  • Loading branch information
kwevers authored and fosterseth committed Jan 24, 2024
1 parent 985a8d4 commit d4f7bfe
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions awx/main/credential_plugins/hashivault.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def method_auth(**kwargs):
cacert = kwargs.get('cacert', None)

sess = requests.Session()
sess.mount(url, requests.adapters.HTTPAdapter(max_retries=5))

# Namespace support
if kwargs.get('namespace'):
Expand Down Expand Up @@ -263,6 +264,7 @@ def kv_backend(**kwargs):
}

sess = requests.Session()
sess.mount(url, requests.adapters.HTTPAdapter(max_retries=5))
sess.headers['Authorization'] = 'Bearer {}'.format(token)
# Compatibility header for older installs of Hashicorp Vault
sess.headers['X-Vault-Token'] = token
Expand Down Expand Up @@ -333,6 +335,7 @@ def ssh_backend(**kwargs):
request_kwargs['json']['valid_principals'] = kwargs['valid_principals']

sess = requests.Session()
sess.mount(url, requests.adapters.HTTPAdapter(max_retries=5))
sess.headers['Authorization'] = 'Bearer {}'.format(token)
if kwargs.get('namespace'):
sess.headers['X-Vault-Namespace'] = kwargs['namespace']
Expand Down

0 comments on commit d4f7bfe

Please sign in to comment.