Skip to content

Commit

Permalink
chore(rcm): get connection on every request (#6753)
Browse files Browse the repository at this point in the history
We get the connection on every request to ensure that the agent is
actually still available. If not, we might be attempting to read from an
invalid connection, causing the I/O operation to block.

## Checklist

- [x] Change(s) are motivated and described in the PR description.
- [x] Testing strategy is described if automated tests are not included
in the PR.
- [x] Risk is outlined (performance impact, potential for breakage,
maintainability, etc).
- [x] Change is maintainable (easy to change, telemetry, documentation).
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed. If no release note is required, add label
`changelog/no-changelog`.
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/)).
- [x] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist

- [x] Title is accurate.
- [x] No unnecessary changes are introduced.
- [x] Description motivates each change.
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes unless absolutely necessary.
- [x] Testing strategy adequately addresses listed risk(s).
- [x] Change is maintainable (easy to change, telemetry, documentation).
- [x] Release note makes sense to a user of the library.
- [x] Reviewer has explicitly acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment.
- [x] Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
- [x] If this PR touches code that signs or publishes builds or
packages, or handles credentials of any kind, I've requested a review
from `@DataDog/security-design-and-guidance`.
- [x] This PR doesn't touch any of that.
  • Loading branch information
P403n1x87 authored Aug 25, 2023
1 parent 4b22fc3 commit f673d29
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ddtrace/internal/remoteconfig/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ def __init__(self):
tracer_version = _pep440_to_semver()

self.id = str(uuid.uuid4())
self.agent_url = agent_url = agent.get_trace_url()
self._conn = agent.get_connection(agent_url, timeout=agent.get_trace_agent_timeout())
self.agent_url = agent.get_trace_url()

self._headers = {"content-type": "application/json"}
additional_header_str = os.environ.get("_DD_REMOTE_CONFIGURATION_ADDITIONAL_HEADERS")
Expand Down Expand Up @@ -257,14 +256,15 @@ def _send_request(self, payload):
log.debug(
"[%s][P: %s] Requesting RC data from products: %s", os.getpid(), os.getppid(), str(self._products)
) # noqa: G200
self._conn.request("POST", REMOTE_CONFIG_AGENT_ENDPOINT, payload, self._headers)
resp = self._conn.getresponse()
conn = agent.get_connection(self.agent_url, timeout=agent.get_trace_agent_timeout())
conn.request("POST", REMOTE_CONFIG_AGENT_ENDPOINT, payload, self._headers)
resp = conn.getresponse()
data = resp.read()
except OSError as e:
log.debug("Unexpected connection error in remote config client request: %s", str(e)) # noqa: G200
return None
finally:
self._conn.close()
conn.close()

if resp.status == 404:
# Remote configuration is not enabled or unsupported by the agent
Expand Down

0 comments on commit f673d29

Please sign in to comment.