ruby: add skip_native_resume to avoid tail call exhaustion (upstream prep)#38
Draft
ruby: add skip_native_resume to avoid tail call exhaustion (upstream prep)#38
Conversation
3f9c997 to
8b34059
Compare
dalehamel
commented
Apr 8, 2026
Member
Author
dalehamel
left a comment
There was a problem hiding this comment.
Review assisted by pair-review
ccfc6fa to
bbf12f7
Compare
When the Ruby unwinder encounters a cfunc (C-implemented Ruby method), it normally transitions back to the native unwinder to unwind through the C code, then re-enters the Ruby unwinder when it detects the Ruby interpreter loop. Each such round-trip costs 2-3 tail calls out of a budget of 29, so a Ruby stack with 10+ cfuncs can easily truncate. This adds a skip_native_resume flag to RubyProcInfo that, when set, pushes cfunc frames inline without transitioning to the native unwinder. This trades native frames within cfuncs (e.g., the C call chain inside Array#sort) for complete Ruby-level traces without truncation. The flag is controlled by OTEL_EBPF_RUBY_SKIP_NATIVE_RESUME (default: false). Set to 'true' to enable.
- Correct inline comment that incorrectly stated 'Default to skipping' when the actual default is false (requires explicit opt-in) - Add note that skipNativeResume() is evaluated per-process at attach time
When skip_native_resume is true, the end-of-stack check should stop instead of resuming native unwinding. Without this, the native unwinder can re-enter the Ruby unwinder from JIT anonymous mappings, pushing frames in wrong positions.
bbf12f7 to
f947f92
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebased version of Shopify PR #31 for staging before upstream submission.
BPF blobs will need rebuilding.