Skip to content

fix: native rust fix for HAMT/ContextVar crash [backport 4.9] - #18709

Merged
KowalskiThomas merged 1 commit into
4.9from
kowalski/backport-18599-to-4.9
Jun 23, 2026
Merged

KowalskiThomas merged 1 commit into
4.9from
kowalski/backport-18599-to-4.9

Conversation

@KowalskiThomas

Copy link
Copy Markdown
Collaborator

Backport of PR #18599 (branch kowalski/fix-fancy-rust-fix-for-hamt-crash) to branch 4.9.

Description

This is an attempt to fix a customer-reported crash (Jira).

This fix addresses the issue in a sort of makeshift way like the CPython upstream fix would. Since we can't bump reference counts directly from CPython, the PR adds a Rust helper which takes care of it. Not great, not terrible.

Note the bug only happens in versions prior to 3.12 (which made significant changes to the GC and doesn't trigger that HAMT crash anymore), so the fix is gated to them.

Notes on conflict resolution

Applied manually to the release branch. contextvar::register_contextvar is wired into each branch's src/native/lib.rs layout (4.8 uses utils instead of ddtrace_utils; 4.11 registers after event_hub).

@KowalskiThomas
KowalskiThomas requested review from a team as code owners June 23, 2026 14:38
@KowalskiThomas
KowalskiThomas requested review from P403n1x87 and rachelyangdog and removed request for a team June 23, 2026 14:38
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Codeowners resolved as

ddtrace/_trace/provider.py                                              @DataDog/apm-sdk-capabilities-python
ddtrace/internal/native/_native.pyi                                     @DataDog/apm-core-python
releasenotes/notes/internal-add-contextvar-helper-d73542f1c6cfceac.yaml  @DataDog/apm-python
src/native/contextvar.rs                                                @DataDog/apm-core-python
src/native/lib.rs                                                       @DataDog/apm-core-python

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

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

@pr-commenter

pr-commenter Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-06-23 16:32:08

Comparing candidate commit 993928d in PR branch kowalski/backport-18599-to-4.9 with baseline commit 89ff0ed in branch 4.9.

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

scenario:iastaspects-lstrip_aspect

  • 🟥 execution_time [+43.982µs; +51.250µs] or [+15.659%; +18.246%]

scenario:iastaspects-translate_aspect

  • 🟥 execution_time [+47.530µs; +58.650µs] or [+9.424%; +11.629%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+97.875µs; +105.429µs] or [+22.475%; +24.210%]

scenario:span-start

  • 🟥 execution_time [+1.443ms; +1.615ms] or [+9.214%; +10.311%]

scenario:telemetryaddmetric-1-count-metric-1-times

  • 🟥 execution_time [+164.146ns; +194.684ns] or [+7.699%; +9.131%]

Route ContextVar activation through a native helper on CPython < 3.12 to
pin context storage across PyContextVar_Set and avoid a rare HAMT/GC
SEGV_MAPERR crash.

Backport of kowalski/fix-fancy-rust-fix-for-hamt-crash.
@KowalskiThomas
KowalskiThomas force-pushed the kowalski/backport-18599-to-4.9 branch from 0291d00 to 993928d Compare June 23, 2026 15:57
@KowalskiThomas
KowalskiThomas enabled auto-merge (squash) June 23, 2026 16:13
@KowalskiThomas
KowalskiThomas merged commit fa1d65e into 4.9 Jun 23, 2026
1159 checks passed
@KowalskiThomas
KowalskiThomas deleted the kowalski/backport-18599-to-4.9 branch June 23, 2026 16:57
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.

2 participants