Skip to content

Commit

Permalink
Merge pull request #1026 from ruby-agent/RUBY-1424-close-connections-…
Browse files Browse the repository at this point in the history
…on-force-restart

RUBY-1424 Close connections on ForceRestartException
  • Loading branch information
mwear committed Mar 17, 2015
2 parents 02c9d0c + 824cca5 commit 9a7ab54
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/new_relic/agent/agent.rb
Expand Up @@ -651,7 +651,7 @@ def create_and_run_event_loop
def handle_force_restart(error)
::NewRelic::Agent.logger.debug error.message
drop_buffered_data
@service.reset_metric_id_cache if @service
@service.force_restart if @service
@connect_state = :pending
sleep 30
end
Expand Down
9 changes: 9 additions & 0 deletions lib/new_relic/agent/new_relic_service.rb
Expand Up @@ -86,6 +86,11 @@ def reset_metric_id_cache
@metric_id_cache = {}
end

def force_restart
reset_metric_id_cache
close_shared_connection
end

# takes an array of arrays of spec and id, adds it into the
# metric cache so we can save the collector some work by
# sending integers instead of strings the next time around
Expand Down Expand Up @@ -244,6 +249,10 @@ def close_shared_connection
end
end

def has_shared_connection?
!@shared_tcp_connection.nil?
end

def ssl_cert_store
path = cert_file_path
if !@ssl_cert_store || path != @cached_cert_store_path
Expand Down
2 changes: 2 additions & 0 deletions test/new_relic/agent/agent/start_worker_thread_test.rb
Expand Up @@ -28,7 +28,9 @@ def test_handle_force_restart

self.expects(:drop_buffered_data)
self.expects(:sleep).with(30)

@connected = true
@service = mock('service', :force_restart => nil)

handle_force_restart(error)

Expand Down
12 changes: 12 additions & 0 deletions test/new_relic/agent/new_relic_service_test.rb
Expand Up @@ -825,6 +825,18 @@ def test_supportability_metrics_with_serialization_failure
])
end

def test_force_restart_clears_metric_cache
@service.metric_id_cache[1] = "boo"
@service.force_restart
assert_empty @service.metric_id_cache
end

def test_force_restart_closes_shared_connections
@service.establish_shared_connection
@service.force_restart
refute @service.has_shared_connection?
end

def build_stats_hash(items={})
hash = NewRelic::Agent::StatsHash.new
items.each do |key, value|
Expand Down

0 comments on commit 9a7ab54

Please sign in to comment.