Skip to content

Commit

Permalink
filters/thread_filter: fixed segfault on Ruby 2.1.3
Browse files Browse the repository at this point in the history
Fixes #229 (Another segfault report)

Ruby segfaults whenever it tries to access `:__recursive_key__`.
Unfortunately, there's no other good way to avoid this segfault.
`:__recursive_key__` is set by PrettyPrint, so it's very common.
  • Loading branch information
kyrylo committed Jun 7, 2017
1 parent 26a2c1b commit 41d84ab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,9 @@ Airbrake Ruby Changelog

### master

* Fixed segfault in `ThreadFilter` on Ruby 2.1.3
([#228](https://github.com/airbrake/airbrake-ruby/pull/228))

### [v2.2.5][v2.2.5] (May 23, 2017)

* Fixed bug when the block form of `notify` would run its block for ignored
Expand Down
8 changes: 8 additions & 0 deletions lib/airbrake-ruby/filters/thread_filter.rb
Expand Up @@ -21,6 +21,13 @@ class ThreadFilter
Numeric
].freeze

##
# @return [Array<Symbol>] the list of ignored fiber variables
IGNORED_FIBER_VARIABLES = [
# https://github.com/airbrake/airbrake-ruby/issues/229
:__recursive_key__
].freeze

def initialize
@weight = 110
end
Expand Down Expand Up @@ -57,6 +64,7 @@ def thread_variables(th)

def fiber_variables(th)
th.keys.map.with_object({}) do |key, h|
next if IGNORED_FIBER_VARIABLES.any? { |v| v == key }
h[key] = sanitize_value(th[key])
end
end
Expand Down
12 changes: 12 additions & 0 deletions spec/filters/thread_filter_spec.rb
Expand Up @@ -119,6 +119,18 @@ def new_thread
)
end
end

it "ignores the :__recursive_key__ fiber variable" do
key = :__recursive_key__

new_thread do |th|
th[key] = key
subject.call(notice)
end

fiber_variables = notice[:params][:thread][:fiber_variables]
expect(fiber_variables[key]).to be_nil
end
end

describe "fiber variables" do
Expand Down

0 comments on commit 41d84ab

Please sign in to comment.