fix(profiling): never enable fast copy memory if interpreter is embedded [backport 4.12] - #19927
fix(profiling): never enable fast copy memory if interpreter is embedded [backport 4.12]#19927KowalskiThomas wants to merge 1 commit into
Conversation
Codeowners resolved as |
Circular import analysis
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f70c1b6626
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Fast memory copy (safe_memcpy) relies on installing SIGSEGV/SIGBUS signal handlers to recover from faults. When Python is embedded in another process (e.g. the Datadog Agent), those handlers can displace signal handlers owned by the host process and cause crashes. This change detects whether the interpreter is embedded (by checking whether the process executable looks like a Python binary) and, if so, skips installing the signal handlers and disables fast copy on both the native (vm.cc) and Python config (profiling.py) sides.
f70c1b6 to
1b3741d
Compare
Backport of PR #19920 to branch
4.12.Description
This PR changes the logic for the enablement of fast copy memory (signal handler-based) to never install signal handlers / try to use fast copy memory when the Python interpreter is running embedded in another application.
The reason we originally want to do that is we received crash reports originating from the Datadog Agent where running Python instrumentation in the Agent caused the Agent to crash. It makes sense generally speaking to be as quiet as possible, and as non-dangerous as possible, when running within another process. Hence this change.
Notes on conflict resolution
The
4.12branch'sddtrace/internal/settings/profiling.pyhas diverged structurally frommain(it lacks the native heap / exception-profiling availability checks and themax_frames/gc_enabledconfig options present onmain). The equivalent change was applied by hand:_is_python_embedded()helper and its imports (os,sys).config.stack.fast_copyoverride in the same style as the other availability-override blocks in this file (after thestack_is_availablecheck, before tag enrichment), since4.12has no laterreport_configuration(config)call to place it before.vm.ccand the new test file/CMakeLists.txt entries were unchanged frommainand applied as-is.Note: source PR #19920 was not yet merged at the time this backport was prepared (approved and mergeable); this backport is created from its current head commit.