Skip to content
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

(locals) gracefully handle binding error when on a Fiber #1095

Merged
merged 1 commit into from
Jun 28, 2022

Conversation

waltjones
Copy link
Contributor

Description of the change

Background

TracePoint#binding cannot be called from a Fiber, though I haven't seen anywhere that this is documented. This can be confirmed by reviewing the location where the exception is raised in Ruby:
https://github.com/ruby/ruby/blob/744d17ff6c33b09334508e8110007ea2a82252f5/vm.c#L1240

And of course it can be confirmed by calling binding while on a Fiber. The above exception will be produced.

In the reported issue, the error happens when next is called on an Enumerator instance. Calling next causes execution to switch to a Fiber.
https://github.com/ice-cube-ruby/ice_cube/blob/2cdfdbaf75bd809831df1af3f0e96639bbc69ee6/lib/ice_cube/schedule.rb#L217

When local variable capture is enabled in rollbar-gem, the stack frames within the Fiber context are captured. The reported issue happens because TracePoint#binding is called while capturing these frames.

Fix

This PR rescues the failed attempt to get the binding and returns nil. Later when building the payload, it skips insertion of locals for frames where the binding is missing.

Type of change

  • Bug fix (non-breaking change that fixes an issue)

Related issues

Fixes: #1094

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • "Ready for review" label attached to the PR and reviewers assigned
  • Issue from task tracker has a link to this pull request
  • Changes have been reviewed by at least one other engineer

Copy link

@cyrusradfar cyrusradfar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for documenting the changes so clearly

@waltjones waltjones merged commit caa82a9 into master Jun 28, 2022
@waltjones waltjones deleted the waltjones/1094/locals-handle-fiber-context branch June 27, 2023 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ruby-On-Rails SDK - Local variable tracking - Runtime Error
2 participants