Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ddtrace/internal/datadog/profiling/stack/src/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ stack_init()
{
// At just do start-of-process cleanup (e.g., set PID)
stack_postfork_cleanup();

// The fork handler is registered at library load time to make sure it
// is registered before dd_wrapper's.
// The rationale is that both stack and dd_wrapper have post-fork hooks;
// and stack needs dd_wrapper's hooks to have completed as it needs the
// Profile object to have been reset and be ready for use, and post-fork
// hooks are executed in LIFO order.
// More details in https://github.com/DataDog/dd-trace-py/pull/17183
pthread_atfork(nullptr, nullptr, stack_atfork_child);
}

void
Expand All @@ -359,7 +368,6 @@ Sampler::one_time_setup()
// It is unlikely, but possible, that the caller has forked since application startup, but before starting echion.
// Run the cleanup to ensure that we're tracking the correct process.
stack_postfork_cleanup();
pthread_atfork(nullptr, nullptr, stack_atfork_child);
}

void
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/fix-profiler-postfork-hook-ordering.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
profiling: A rare crash that could occur post-fork in fork-based applications has been fixed.
Loading