Skip to content

Commit

Permalink
RUBY-868 exclude Rails config from flat stack and make sure procs are…
Browse files Browse the repository at this point in the history
… properly handled
  • Loading branch information
gnarg committed Aug 31, 2012
1 parent bc5a38d commit eef5a84
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
23 changes: 18 additions & 5 deletions lib/new_relic/agent/configuration/manager.rb
Expand Up @@ -61,12 +61,25 @@ def fetch(key)
end

def flattened_config
@config_stack.reverse.inject({}) do |flat,stack|
thawed_stack = stack.dup
thawed_stack.each do |k,v|
thawed_stack[k] = instance_eval(&v) if v.respond_to?(:call)
@config_stack.reverse.inject({}) do |flat,layer|
thawed_layer = layer.dup
thawed_layer.each do |k,v|
begin
thawed_layer[k] = instance_eval(&v) if v.respond_to?(:call)
rescue => e
NewRelic::Control.instance.log.debug("#{e.class.name} : #{e.message} - when calling Proc for config key #{k}")
thawed_layer[k] = nil
end
exclude_rails_config(thawed_layer, k)
end
flat.merge(thawed_stack)
flat.merge(thawed_layer)
end
end

def exclude_rails_config(hash, key)
if defined?(::Rails::Configuration) &&
hash[key].kind_of?(::Rails::Configuration)
hash.reject!(key)
end
end

Expand Down
8 changes: 6 additions & 2 deletions lib/new_relic/agent/new_relic_service.rb
Expand Up @@ -119,7 +119,9 @@ def invoke_remote(method, *args)
# big payloads get all the compression possible, to stay under
# the 2,000,000 byte post threshold
def compress_data(object)
dump = Marshal.dump(object)
dump = NewRelic::LanguageSupport.with_cautious_gc do
Marshal.dump(object)
end

dump_size = dump.size

Expand Down Expand Up @@ -200,7 +202,9 @@ def decompress_response(response)
# so we can handle it in nonlocally
def check_for_exception(response)
dump = decompress_response(response)
value = Marshal.load(dump)
value = NewRelic::LanguageSupport.with_cautious_gc do
Marshal.load(dump)
end
raise value if value.is_a? Exception
value
end
Expand Down
11 changes: 5 additions & 6 deletions lib/new_relic/agent/pipe_channel_manager.rb
Expand Up @@ -41,7 +41,10 @@ def close

def write(data)
@out.close unless @out.closed?
@in << Marshal.dump(data) + "\n\n"
@in << NewRelic::LanguageSupport.with_cautious_gc do
Marshal.dump(data)
end
@in << "\n\n"
end

def read
Expand Down Expand Up @@ -137,11 +140,7 @@ def merge_data_from_pipe(pipe_handle)
end

def unmarshal(data)
if NewRelic::LanguageSupport.broken_gc?
NewRelic::LanguageSupport.with_disabled_gc do
Marshal.load(data)
end
else
NewRelic::LanguageSupport.with_cautious_gc do
Marshal.load(data)
end
rescue StandardError => e
Expand Down
8 changes: 8 additions & 0 deletions lib/new_relic/language_support.rb
Expand Up @@ -82,6 +82,14 @@ def with_disabled_gc
end
end

def with_cautious_gc
if broken_gc?
with_disabled_gc { yield }
else
yield
end
end

def using_version?(version)
numbers = version.split('.')
numbers == ::RUBY_VERSION.split('.')[0, numbers.size]
Expand Down

0 comments on commit eef5a84

Please sign in to comment.