-
Notifications
You must be signed in to change notification settings - Fork 18.4k
runtime: limit total frames traversed during stack walking #75764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Stack walking in tracebackPCs now limits the total number of frames traversed, including wrapper frames, to prevent excessive CPU time when unwinding stacks with very deep context chains. Previously, tracebackPCs only limited the number of output frames (64) but would traverse all wrapper frames without limit. With extremely deep context chains (e.g., 10 million layers), this could cause stack walking to take seconds, as wrapper frames for methods like context.(*valueCtx).Deadline are traversed but not counted toward the output limit. This change adds a maxTotalFrames constant (1024) to cap the total number of physical frames walked. This is high enough for normal stack traces while preventing multi-second delays in CPU profiling and other stack walking scenarios. Fixes golang#75583
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
This PR (HEAD: 49e1dc9) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/709396. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/709396. |
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/709396. |
Fixes #75583
The issue happens because tracebackPCs only limits the number of output frames (64 for CPU profiler) but keeps traversing all wrapper frames. With deep context chains, this means walking through millions of wrapper frames from context.(*valueCtx).Deadline calls, which causes the profiler to hang for seconds.
The fix adds a hard limit of 1024 total frames to walk through. This is enough for normal cases but prevents the pathological behavior with deep contexts.
Testing