Skip to content

fix: native rust fix for HAMT/ContextVar crash - #18599

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
mainfrom
kowalski/fix-fancy-rust-fix-for-hamt-crash
Jun 24, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
mainfrom
kowalski/fix-fancy-rust-fix-for-hamt-crash

Conversation

@KowalskiThomas

@KowalskiThomas KowalskiThomas commented Jun 12, 2026 •

Copy link
Copy Markdown
Collaborator

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.


The crash signature is

Error UnixSignal: Process terminated with SEGV_MAPERR (SIGSEGV)
#0   0x00000000006a3e3b  
#1   0x0000000000690b5b  
#2   0x00000000004a5e01  
#3   0x0000000000690a27  
#4   0x0000000000690990  
#5   0x0000000000690699 PyContextVar_Set 
#6   0x0000000000540be3 _PyEval_EvalFrameDefault 
#7   0x0000000000585937  
#8   0x000000000058512e  
#9   0x000000000054aea5 PyObject_Vectorcall 
#10  0x000000000053d7a6 _PyEval_EvalFrameDefault 
#11  0x0000000000585040  
#12  0x0000000000541c19 _PyEval_EvalFrameDefault 
#13  0x0000000000583177  
#14  0x0000000000581a14  
#15  0x00000000005b418d  
#16  0x000000000053fb96 _PyEval_EvalFrameDefault 
#17  0x00000000005afd4e  
#18  0x00000000005bf334  
#19  0x000000000053f6b2 _PyEval_EvalFrameDefault 
#20  0x0000000000585937  
#21  0x000000000058512e  
#22  0x0000000000570534 PyObject_Call 
#23  0x0000000000541c19 _PyEval_EvalFrameDefault 
#24  0x0000000000565f43 _PyFunction_Vectorcall 
#25  0x00000000005341e9 _PyObject_FastCallDictTstate 
#26  0x000000000056e0f9 _PyObject_Call_Prepend 
#27  0x000000000065a02b  
#28  0x000000000052f59c _PyObject_MakeTpCall 
#29  0x000000000053d7a6 _PyEval_EvalFrameDefault 
#30  0x00000000006140f4  
#31  0x0000000000613757 PyEval_EvalCode 
#32  0x00000000006344eb  
#33  0x0000000000630744  
#34  0x0000000000644be5  
#35  0x00000000006441f4 _PyRun_SimpleFileObject 
#36  0x0000000000644007 _PyRun_AnyFileObject 
#37  0x000000000063ed19 Py_RunMain 
#38  0x00000000006049cd Py_BytesMain 
#39  0x00007f3bd11a6d90 __libc_start_call_main (sysdeps/nptl/libc_start_call_main.h:58)
#40  0x0000000000000000 call_init (csu/libc-start.c:128)
#41  0x00007f3bd11a6e40 call_init (csu/libc-start.c:128)
#42  0x00007f3bd11a6e40 __libc_start_main_alias_2 (csu/libc-start.c:379)
#43  0x0000000000604855 _start 

@KowalskiThomas
KowalskiThomas force-pushed the kowalski/fix-fancy-rust-fix-for-hamt-crash branch from 01ffcf6 to 24eb7d0 Compare June 12, 2026 12:15
@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Pipelines  Tests

✨ Fix all issues with BitsAI

⚠️ Warnings

🚦 8 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-py | build linux serverless: [amd64, cp315-cp315, v113741238-d2b8243-manylinux2014_x86_64, 1]   View in Datadog   GitLab

DataDog/apm-reliability/dd-trace-py | build linux serverless: [amd64, cp315-cp315, v113741491-d2b8243-musllinux_1_2_x86_64, 1]   View in Datadog   GitLab

DataDog/apm-reliability/dd-trace-py | build linux serverless: [arm64, cp315-cp315, v113741357-d2b8243-manylinux2014_aarch64, 1]   View in Datadog   GitLab

View all 8 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

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

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Jun 12, 2026 •

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

@KowalskiThomas
KowalskiThomas force-pushed the kowalski/fix-fancy-rust-fix-for-hamt-crash branch 3 times, most recently from 94735b4 to 1fa86bd Compare June 12, 2026 12:34
@pr-commenter

pr-commenter Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-06-23 14:33:06

Comparing candidate commit e0b4bb5 in PR branch kowalski/fix-fancy-rust-fix-for-hamt-crash with baseline commit 17ff831 in branch main.

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

scenario:iastaspects-ljust_aspect

  • 🟥 execution_time [+62.747µs; +74.169µs] or [+10.674%; +12.617%]

scenario:iastaspects-stringio_noaspect

  • 🟥 execution_time [+32.983µs; +39.087µs] or [+8.782%; +10.407%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+89.582µs; +97.860µs] or [+20.414%; +22.301%]

scenario:span-start

  • 🟥 execution_time [+1.344ms; +1.491ms] or [+8.736%; +9.694%]

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

  • 🟥 execution_time [+239.043ns; +272.554ns] or [+11.471%; +13.079%]

@KowalskiThomas KowalskiThomas changed the title fix: fancy rust fix for hamt crash fix: native rust fix for hamt crash Jun 12, 2026
@KowalskiThomas KowalskiThomas changed the title fix: native rust fix for hamt crash fix: native rust fix for HAMT/ContextVar crash Jun 12, 2026
@KowalskiThomas
KowalskiThomas force-pushed the kowalski/fix-fancy-rust-fix-for-hamt-crash branch from 5225b92 to 1987e8b Compare June 18, 2026 08:43
@KowalskiThomas
KowalskiThomas marked this pull request as ready for review June 22, 2026 05:04
@KowalskiThomas
KowalskiThomas requested review from a team as code owners June 22, 2026 05:04

@brettlangdon brettlangdon 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.

small release note nit, but otherwise lgtm

Comment thread releasenotes/notes/internal-add-contextvar-helper-d73542f1c6cfceac.yaml Outdated
Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com>
@github-actions

Copy link
Copy Markdown
Contributor

This change is marked for backport to 4.10, but it conflicts with that branch.
Attempting to cherrypick this change to 4.10 yielded the following error:

Auto-merging ddtrace/internal/native/_native.pyi
CONFLICT (content): Merge conflict in ddtrace/internal/native/_native.pyi
Auto-merging src/native/lib.rs
CONFLICT (content): Merge conflict in src/native/lib.rs
error: could not apply 3886a01b93... Merge e0b4bb5ba265e2480478c810c3dd20b07c8c7f46 into 3776154ce7039bee1c787849df5ac1e09a8f797c

The command used to test backporting was

git fetch origin 4.10 && git checkout origin/4.10 && git checkout -b backport-18599-to-4.10 && git cherry-pick -x --mainline 1 3886a01b931d950846b7e6051182a59cb4a4e3d2

@github-actions

Copy link
Copy Markdown
Contributor

This change is marked for backport to 4.8, but it conflicts with that branch.
Attempting to cherrypick this change to 4.8 yielded the following error:

Auto-merging ddtrace/internal/native/_native.pyi
CONFLICT (content): Merge conflict in ddtrace/internal/native/_native.pyi
Auto-merging src/native/lib.rs
CONFLICT (content): Merge conflict in src/native/lib.rs
error: could not apply 3886a01b93... Merge e0b4bb5ba265e2480478c810c3dd20b07c8c7f46 into 3776154ce7039bee1c787849df5ac1e09a8f797c

The command used to test backporting was

git fetch origin 4.8 && git checkout origin/4.8 && git checkout -b backport-18599-to-4.8 && git cherry-pick -x --mainline 1 3886a01b931d950846b7e6051182a59cb4a4e3d2

@github-actions

Copy link
Copy Markdown
Contributor

This change is marked for backport to 4.11, but it conflicts with that branch.
Attempting to cherrypick this change to 4.11 yielded the following error:

Auto-merging ddtrace/internal/native/_native.pyi
CONFLICT (content): Merge conflict in ddtrace/internal/native/_native.pyi
Auto-merging src/native/lib.rs
error: could not apply 3886a01b93... Merge e0b4bb5ba265e2480478c810c3dd20b07c8c7f46 into 3776154ce7039bee1c787849df5ac1e09a8f797c

The command used to test backporting was

git fetch origin 4.11 && git checkout origin/4.11 && git checkout -b backport-18599-to-4.11 && git cherry-pick -x --mainline 1 3886a01b931d950846b7e6051182a59cb4a4e3d2

@github-actions

Copy link
Copy Markdown
Contributor

This change is marked for backport to 4.9, but it conflicts with that branch.
Attempting to cherrypick this change to 4.9 yielded the following error:

Auto-merging ddtrace/internal/native/_native.pyi
CONFLICT (content): Merge conflict in ddtrace/internal/native/_native.pyi
Auto-merging src/native/lib.rs
CONFLICT (content): Merge conflict in src/native/lib.rs
error: could not apply 3886a01b93... Merge e0b4bb5ba265e2480478c810c3dd20b07c8c7f46 into 3776154ce7039bee1c787849df5ac1e09a8f797c

The command used to test backporting was

git fetch origin 4.9 && git checkout origin/4.9 && git checkout -b backport-18599-to-4.9 && git cherry-pick -x --mainline 1 3886a01b931d950846b7e6051182a59cb4a4e3d2

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants