fix(tracing): avoid curl's getenv calls#3528
Merged
morrisonlevi merged 2 commits intomasterfrom Dec 12, 2025
Merged
Conversation
Benchmarks [ tracer ]Benchmark execution time: 2025-12-11 18:24:33 Comparing candidate commit 3e24961 in PR branch Found 1 performance improvements and 7 performance regressions! Performance is the same for 186 metrics, 0 unstable metrics. scenario:MessagePackSerializationBench/benchMessagePackSerialization
scenario:MessagePackSerializationBench/benchMessagePackSerialization-opcache
scenario:SamplingRuleMatchingBench/benchRegexMatching1
scenario:SamplingRuleMatchingBench/benchRegexMatching2
scenario:SamplingRuleMatchingBench/benchRegexMatching3
scenario:SamplingRuleMatchingBench/benchRegexMatching4
scenario:SpanBench/benchOpenTelemetryAPI
scenario:TraceSerializationBench/benchSerializeTrace
|
realFlowControl
approved these changes
Dec 12, 2025
Member
|
Thanks for fixing this, we should get this (and the other tings lined up) shipped this week. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
There’s a long‑standing crash caused by libcurl calling
getenvfrom our background writer thread. We’ve often mitigated this by telling customers to use the sidecar sender instead, but since the sidecar is still not the default and this issue still happens weekly, roughly 3k per week across all of our customers, this PR addresses the root cause in the BGS path.The typical backtrace looks like this:
Curl is reading proxy configuration from environment variables (e.g. <scheme>_proxy, all_proxy, no_proxy), which internally goes through
curl_getenv, which callsgetenvon Linux.Technical Fix
We now snapshot the relevant proxy environment variables once during MINIT, store them in process globals, and then configure our libcurl handles so that libcurl no longer needs to call curl_getenv in the writer thread.
New/changed pieces:
ddtrace_coms_minit_proxy_env: called from MINIT to read andstrdupthe proxy‑related env vars.ddtrace_coms_mshutdown_proxy_env: called from MSHUTDOWN (after the writer has been shut down) to free those cached strings.ddtrace_curl_set_hostname_generic: now always sets CURLOPT_NOPROXY (using the cached no_proxy/NO_PROXY value or "") and, when appropriate, CURLOPT_PROXY based on the cached proxy envs, so libcurl’s internal proxy detection never hitscurl_getenvfor these handles.Testing
Due to the nature of the race, it's difficult to write an automated test for it. I set up a reproducer environment, and even there it's difficult for me to get it to trigger.
But I wrote with a
getenvwrapper loaded throughLD_PRELOAD:And when I run it on master, I see that these env vars were being looked up by curl (using Debian, can vary a bit precisely depending on how curl was built):
no_proxyhttp_proxyAnd with this branch, those are gone.
Reviewer checklist