lib/new_relic/agent/agent.rb in newrelic_rpm-3.12.1.298 vs lib/new_relic/agent/agent.rb in newrelic_rpm-3.13.0.299

- old
+ new

@@ -69,10 +69,12 @@ @connect_state = :pending @connect_attempts = 0 @environment_report = nil + @wait_on_connect_reader, @wait_on_connect_writer = IO.pipe + @obfuscator = lambda {|sql| NewRelic::Agent::Database.default_sql_obfuscator(sql) } setup_attribute_filter end @@ -865,10 +867,34 @@ # If you're adding something else here to respond to the server-side config, # use Agent.instance.events.subscribe(:finished_configuring) callback instead! end + class WaitOnConnectTimeout < StandardError + end + + # Used for testing to let us know we've actually started to wait + def waited_on_connect? + @waited_on_connect + end + + def signal_connected + @wait_on_connect_writer << "." + end + + def wait_on_connect(timeout) + return if connected? + + @waited_on_connect = true + NewRelic::Agent.logger.debug("Waiting on connect to complete.") + IO.select([@wait_on_connect_reader], nil, nil, timeout) + + unless connected? + raise WaitOnConnectTimeout, "Agent was unable to connect in #{timeout} seconds." + end + end + # Logs when we connect to the server, for debugging purposes # - makes sure we know if an agent has not connected def log_connection!(config_data) ::NewRelic::Agent.logger.debug "Connected to NewRelic Service at #{@service.collector.name}" ::NewRelic::Agent.logger.debug "Agent Run = #{@service.agent_id}." @@ -934,9 +960,10 @@ ::NewRelic::Agent.logger.debug "Connecting Process to New Relic: #$0" query_server_for_configuration @connected_pid = $$ @connect_state = :connected + signal_connected rescue NewRelic::Agent::ForceDisconnectException => e handle_force_disconnect(e) rescue NewRelic::Agent::LicenseException => e handle_license_error(e) rescue NewRelic::Agent::UnrecoverableAgentException => e