@@ -30,7 +30,7 @@ public class SharedCommunicationObjects {
3030 public OkHttpClient okHttpClient ;
3131 public HttpUrl agentUrl ;
3232 public Monitoring monitoring ;
33- private DDAgentFeaturesDiscovery featuresDiscovery ;
33+ private volatile DDAgentFeaturesDiscovery featuresDiscovery ;
3434 private ConfigurationPoller configurationPoller ;
3535
3636 public SharedCommunicationObjects () {
@@ -140,23 +140,27 @@ public void setFeaturesDiscovery(DDAgentFeaturesDiscovery featuresDiscovery) {
140140
141141 public DDAgentFeaturesDiscovery featuresDiscovery (Config config ) {
142142 if (featuresDiscovery == null ) {
143- createRemaining (config );
144- featuresDiscovery =
145- new DDAgentFeaturesDiscovery (
146- okHttpClient ,
147- monitoring ,
148- agentUrl ,
149- config .isTraceAgentV05Enabled (),
150- config .isTracerMetricsEnabled ());
151-
152- if (paused ) {
153- // defer remote discovery until remote I/O is allowed
154- } else {
155- if (AGENT_THREAD_GROUP .equals (Thread .currentThread ().getThreadGroup ())) {
156- featuresDiscovery .discover (); // safe to run on same thread
157- } else {
158- // avoid performing blocking I/O operation on application thread
159- AgentTaskScheduler .INSTANCE .execute (featuresDiscovery ::discover );
143+ synchronized (this ) {
144+ if (featuresDiscovery == null ) {
145+ createRemaining (config );
146+ featuresDiscovery =
147+ new DDAgentFeaturesDiscovery (
148+ okHttpClient ,
149+ monitoring ,
150+ agentUrl ,
151+ config .isTraceAgentV05Enabled (),
152+ config .isTracerMetricsEnabled ());
153+
154+ if (paused ) {
155+ // defer remote discovery until remote I/O is allowed
156+ } else {
157+ if (AGENT_THREAD_GROUP .equals (Thread .currentThread ().getThreadGroup ())) {
158+ featuresDiscovery .discover (); // safe to run on same thread
159+ } else {
160+ // avoid performing blocking I/O operation on application thread
161+ AgentTaskScheduler .INSTANCE .execute (featuresDiscovery ::discover );
162+ }
163+ }
160164 }
161165 }
162166 }
0 commit comments