-
Notifications
You must be signed in to change notification settings - Fork 305
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 http leak #272
fix http leak #272
Conversation
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.
Almost good to go, thank you so much for this important fix! I'd love us to use a context manager though... 😊
datadog/api/http_client.py
Outdated
@@ -94,6 +94,8 @@ def request(cls, method, url, headers, params, data, timeout, proxies, verify, m | |||
u"Datadog's usage. We recommand upgrading it ('pip install -U requests')." | |||
u"If you need help or have any question, please contact support@datadoghq.com" | |||
) | |||
finally: |
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.
Although this is 100% fine, I think I would prefer if we could use requests
context manager for sessions...
we can basically wrap the entire method with:
with requests.Session() as s:
http_adapter = requests.adapters.HTTPAdapter(max_retries=max_retries)
s.mount('https://', http_adapter)
# REST OF METHOD...
If you don't want to update that, just let me know as this is blatant nitpicking, and we can merge this as is!
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.
updated
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.
let me know what you think
btw, for future reference, with help I found one of the leaks was due to python/cpython#4587, because this would cause a warning of unclosed socket |
failures don't seem related to my change |
Thanks @thehesiod ! |
fixes #271