Skip to content

fix(profiling): upper bound on iterations for TaskInfo::unwind [backport 4.5]#16542

Merged
emmettbutler merged 1 commit into4.5from
backport-16510-to-4.5
Feb 17, 2026
Merged

fix(profiling): upper bound on iterations for TaskInfo::unwind [backport 4.5]#16542
emmettbutler merged 1 commit into4.5from
backport-16510-to-4.5

Conversation

@dd-octo-sts
Copy link
Contributor

@dd-octo-sts dd-octo-sts bot commented Feb 17, 2026

Backport #16510 to 4.5

)

## Description

This PR updates the Task unwinding logic for the Profiler to have an upper bound on the number of (1) Tasks in the Task chain unwound (2) coroutines in the coroutine chain unwound.

This is important because if somehow we have some memory corruption (very possible, as we don't take a snapshot of the interpreter memory but rather copy select "chunks" over time, and the state of Tasks can change as we copy those "chunks"), we could otherwise end up looping infinitely (which is bad for obvious reasons) and as a result try to add an infinite number of items to the Frame Stack (which is arguably significantly worse, as this would mean trying to allocate an infinite amount of memory 💣).

We spotted this issue when we deployed `4.5.0rc2` to internal Rapid Python HTTP services, see IR-49542.

Co-authored-by: thomas.kowalski <thomas.kowalski@datadoghq.com>
(cherry picked from commit 0cfe067)
Signed-off-by: Emmett Butler <emmett.butler321@gmail.com>
@dd-octo-sts dd-octo-sts bot requested review from a team as code owners February 17, 2026 19:11
@cit-pr-commenter-54b7da
Copy link

Codeowners resolved as

ddtrace/internal/datadog/profiling/stack/src/echion/tasks.cc            @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/echion/threads.cc          @DataDog/profiling-python
releasenotes/notes/profiling-fix-max-iterations-unwind-tasks-671d743912c7d600.yaml  @DataDog/apm-python

@datadog-official
Copy link
Contributor

datadog-official bot commented Feb 17, 2026

⚠️ Tests

Fix all issues with BitsAI or with Cursor

⚠️ Warnings

❄️ 25 New flaky tests detected

    test_filename_to_package[py3.13] from test_packages.py (Fix with Cursor)

    test_get_distributions[py3.13] from test_packages.py (Fix with Cursor)

    test_third_party_packages_excludes_includes[py3.13] from test_packages.py (Fix with Cursor)

View all

ℹ️ Info

🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 8d30812 | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@emmettbutler emmettbutler merged commit 3523171 into 4.5 Feb 17, 2026
197 of 200 checks passed
@emmettbutler emmettbutler deleted the backport-16510-to-4.5 branch February 17, 2026 19:52
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