-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
feat: Add retries to requests sessions #14740
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'): | ||
|
@@ -263,6 +264,7 @@ def kv_backend(**kwargs): | |
} | ||
|
||
sess = requests.Session() | ||
sess.mount(url, requests.adapters.HTTPAdapter(max_retries=5)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that the sess.post below are already in a retry loop, so I'm wondering if this mount is needed, or how it will work with the retry logic below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
sess.headers['Authorization'] = 'Bearer {}'.format(token) | ||
# Compatibility header for older installs of Hashicorp Vault | ||
sess.headers['X-Vault-Token'] = token | ||
|
@@ -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'] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does HTTPAdapter have backoff between retries? or does it wait a fixed amount of time between posts/gets? is this configurable?
what http code triggers the retry?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTTPAdapter
passes themax_retries
argument tourlopen
fromurllib3.poolmanager.PoolManager
.Based on the description at https://urllib3.readthedocs.io/en/stable/reference/urllib3.connectionpool.html#urllib3.HTTPConnectionPool.urlopen there is no builtin back-off behaviour, unless we use a
Retry
object in which case all of this is configurable.max_retries
is only used for things like DNS lookup errors, connection time outs, ... as soon as the request hit the server this doesn't apply anymore.See https://docs.python-requests.org/en/latest/api/#requests.adapters.HTTPAdapter