Skip to content

Compare ActiveRecord connection cache entries by identity#5890

Merged
ivoanjo merged 5 commits into
masterfrom
marcotc/patch-2
Jun 11, 2026
Merged

Compare ActiveRecord connection cache entries by identity#5890
ivoanjo merged 5 commits into
masterfrom
marcotc/patch-2

Conversation

@marcotc

@marcotc marcotc commented Jun 11, 2026

Copy link
Copy Markdown
Member

Originally #5719, by @dmilisic (thank you!).

What does this PR do?
Fix #5718 Segmentation fault in CachingResolver

Motivation:
Ocasional segfaults after upgrading from ddtrace (v1) to datadog (v2)

Change log entry

Yes. Compare ActiveRecord connection cache entries by identity

Additional Notes:
When using rails with multiple threads, each thread will have its own connection configuration Hash with a different object_id. So we can expect more cache entries, but we eliminate the overhead of comparing hashes.

An equivalent workaround (#5719) ran successfully in production for ~2 weeks without a segfault. Previously, segfaults occurred on a daily basis.

How to test the change?

Segmentation faults are difficult to reproduce. There should be no change in behaviour.

@marcotc
marcotc requested review from a team as code owners June 11, 2026 07:23
@marcotc
marcotc requested review from vpellan and wantsui June 11, 2026 07:23
@dd-octo-sts

dd-octo-sts Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

👋 Hey @marcotc, please fill "Change log entry" section in the pull request description.

If changes need to be present in CHANGELOG.md you can state it this way

**Change log entry**

Yes. A brief summary to be placed into the CHANGELOG.md

(possible answers Yes/Yep/Yeah)

Or you can opt out like that

**Change log entry**

None.

(possible answers No/Nope/None)

Visited at: 2026-06-11 07:23:15 UTC

@dd-octo-sts dd-octo-sts Bot added integrations Involves tracing integrations tracing labels Jun 11, 2026
@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Jun 11, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 89.88% (-0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: f561415 | Docs | Datadog PR Page | Give us feedback!

@pr-commenter

pr-commenter Bot commented Jun 11, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-06-11 07:51:30

Comparing candidate commit f561415 in PR branch marcotc/patch-2 with baseline commit c293349 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 48 metrics, 1 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 ----------------------------------'

@ivoanjo ivoanjo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 LGTM

One thing I'd suggest clarifying in the PR description is that it claims

We're running this fix in production for ~2 weeks without a single segfault. Previously, segfaults ocurred on a daily basis.

and this description came from #5719 which is a different change from this one.

I do agree that they are in theory equivalent. The problem is the Ruby VM in theory shouldn't segfault when doing this, yet it does. So this workaround is about what happens in practice so at least to me I think we should be clear that we expect the workaround to work, but have not actually been able to reproduce the original bug and thus to validate it.

Maybe this is a small detail, but I think it's important to clarify it if we need to revisit the issue in the future.

Comment on lines +108 to +109
# as large change around the crash site was done in that version (https://github.com/ruby/ruby/pull/14039/changes#diff-884a5a8a369ef1b4c7597e00aa65974cec8c5f54f25f03ad5d24848f64892869R1743),
# where `RClass.cc_table` (the NULL dereferenced pointer) became a GC-managed object,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: This comment looks unfinished? (And I'm not sure it's actually related to our crash?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's related to the crash site.
I only typed , instead of ..
I'll fix it.
I'll reread it today to see if it's not clear.

@ivoanjo

ivoanjo commented Jun 11, 2026

Copy link
Copy Markdown
Member

As we have an upcoming release, and we've tested and also approved the previous PR, I'm going to go ahead and merge this PR to make sure it's ready and validated for the release.

I'd still advise:

  • Updating the PR description with my suggestion above
  • Doing a follow-up to fix the weird comment

@ivoanjo
ivoanjo merged commit 0184b53 into master Jun 11, 2026
1144 of 1155 checks passed
@ivoanjo
ivoanjo deleted the marcotc/patch-2 branch June 11, 2026 08:32
@dd-octo-sts dd-octo-sts Bot added this to the 2.36.0 milestone Jun 11, 2026
@eregon

eregon commented Jun 17, 2026

Copy link
Copy Markdown
Member

Nice.
Just one thing for posterity, have we figured out that it's always fine to cache by identity?
i.e. that ActiveRecord always returns the same connection configuration Hash (seems to be spec'd, good) but also that it's the case for all other usages of Datadog::Tracing::Contrib::Configuration::CachingResolver‎?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrations Involves tracing integrations tracing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Segmentation fault in CachingResolver

5 participants