Skip to content

Commit

Permalink
Merge pull request #272 from farmersbusinessnetwork/thehesiod/fix-htt…
Browse files Browse the repository at this point in the history
…p-client-leak

fix http leak
  • Loading branch information
yannmh committed Jun 26, 2018
2 parents 6126c14 + 21514a9 commit f926fe6
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions datadog/api/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# 3p
try:
import requests
import requests.adapters
except ImportError:
requests = None

Expand Down Expand Up @@ -64,19 +65,20 @@ class RequestClient(HTTPClient):
def request(cls, method, url, headers, params, data, timeout, proxies, verify, max_retries):
"""
"""
# Use a session to set a max_retries parameters
s = requests.Session()
http_adapter = requests.adapters.HTTPAdapter(max_retries=max_retries)
s.mount('https://', http_adapter)

try:
result = s.request(
method, url,
headers=headers, params=params, data=data,
timeout=timeout,
proxies=proxies, verify=verify)

result.raise_for_status()
# Use a session to set a max_retries parameters
with requests.Session() as s:
http_adapter = requests.adapters.HTTPAdapter(max_retries=max_retries)
s.mount('https://', http_adapter)

# Since stream=False we can close the session after this call
result = s.request(
method, url,
headers=headers, params=params, data=data,
timeout=timeout,
proxies=proxies, verify=verify)

result.raise_for_status()

except requests.ConnectionError as e:
raise _remove_context(ClientError(method, url, e))
Expand Down

0 comments on commit f926fe6

Please sign in to comment.