Skip to content

Capture proxy related environment variables at Curl client construction to avoid crash#328

Merged
xlamorlette-datadog merged 8 commits into
mainfrom
xlamorlette/fix-curl-getenv-crash
Jun 16, 2026
Merged

Capture proxy related environment variables at Curl client construction to avoid crash#328
xlamorlette-datadog merged 8 commits into
mainfrom
xlamorlette/fix-curl-getenv-crash

Conversation

@xlamorlette-datadog

@xlamorlette-datadog xlamorlette-datadog commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Description

Read the proxy related environment variables when the Curl client is created (in CurlImpl constructor), and, later, pass the values to libcurl explicitly on each request (in CurlImpl::post()).

Motivation

In some (new) tests for the Datadog Nginx module, we get crashes during shutdown.
This is because the tracer's libcurl background thread reads proxy environment variables via getenv() on every new connection. But when Nginx shuts down, it changes its worker's process title, which rewrites its environment. This leads to a segfault due to a race condition.

Additional Notes

This mirrors the approach used in dd-trace-php (in ddtrace_comes_minit_proxy_env()).

I cleaned a bit the surrounding code, notably by extracting CurlImpl::configure_handle() from CurlImpl::post().

…ion to avoid calls to getenv() from libcurl in the worker thread, leading to crashes in some cases
@datadog-official

This comment has been minimized.

@xlamorlette-datadog xlamorlette-datadog force-pushed the xlamorlette/fix-curl-getenv-crash branch from dd05555 to f0bce1d Compare June 12, 2026 17:14
@pr-commenter

pr-commenter Bot commented Jun 12, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-06-12 18:31:48

Comparing candidate commit 6d126a4 in PR branch xlamorlette/fix-curl-getenv-crash with baseline commit d0605a7 in branch main.

Found 3 performance improvements and 0 performance regressions! Performance is the same for 5 metrics, 0 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:BM_TraceID_ParseHex/128bit

  • 🟩 execution_time [-8.852ns; -8.692ns] or [-6.588%; -6.469%]

scenario:BM_TraceID_ParseHex/64bit

  • 🟩 execution_time [-5.826ns; -5.803ns] or [-7.758%; -7.728%]

scenario:BM_TraceTinyCCSource

  • 🟩 execution_time [-2.058ms; -1.654ms] or [-2.627%; -2.111%]

@xlamorlette-datadog xlamorlette-datadog changed the title In CurlImpl, capture proxy related environment variables at construct… Capture proxy related environment variables at construction to avoid crash Jun 12, 2026
@xlamorlette-datadog xlamorlette-datadog marked this pull request as ready for review June 12, 2026 18:46
@xlamorlette-datadog xlamorlette-datadog requested review from a team as code owners June 12, 2026 18:46
@xlamorlette-datadog xlamorlette-datadog requested review from tabgok and removed request for a team June 12, 2026 18:46
@xlamorlette-datadog xlamorlette-datadog changed the title Capture proxy related environment variables at construction to avoid crash Capture proxy related environment variables at Curl client construction to avoid crash Jun 12, 2026
@tabgok tabgok requested review from dubloom and removed request for tabgok June 12, 2026 18:51
Comment thread src/datadog/curl.cpp

@zacharycmontoya zacharycmontoya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one small refactor comment

@xlamorlette-datadog xlamorlette-datadog merged commit 0a1dc56 into main Jun 16, 2026
38 checks passed
@xlamorlette-datadog xlamorlette-datadog deleted the xlamorlette/fix-curl-getenv-crash branch June 16, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants