fix(profiling): null g_saved_alloc_pub after stop() for OBJ domain #20621
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #20621"
general
weight: 0.35
gyuheon0h
Description
While looking at crash reports, I saw a series of crash reports that look like such: https://app.datadoghq.com/error-tracking/issue/4fe0aa66-5607-11f1-b89e-da7ad0900002?query=version%3A4.15.2&et-issue__error-sample-viz=sample&refresh_mode=sliding&from_ts=1789393982142&to_ts=1790603582142&live=true
The crashes are in the memalloc profiler's allocator hook lifecycle caused SIGSEGV crashes in gunicorn/gevent workers (observed as SI_KERNEL at
alloc.malloc(alloc.ctx, ...)inmemalloc_alloc).From looking at the code, I saw that
g_saved_alloc_pubis not nulled after stop() for the OBJ domainmemalloc_stop()restored the original allocator but leftg_saved_alloc_pubnon-null, unlike the MEM domain which correctly storesnullptr. On free-threaded Python (no GIL onPYMEM_DOMAIN_OBJ), any hook that already loaded the non-null pub afterstop()would call through to the saved allocator context after the heap tracker was destroyed.Testing
LOW IMO
g_saved_alloc_pubnullable store runs afterPyMem_SetAllocatorhas already uninstalled the hook. On standard GIL Python the hook can't be called between those two lines anyway. The only observable effect is that after this store, any hook that somehow loaded the pub pointer before it was nulled would see nullptr and fast-exit instead of calling throughRisks
<!-- Note any risks associated with this change, or "None" if no risks -->
Additional Notes