@@ -30,7 +30,7 @@ public class SharedCommunicationObjects {
30
30
public OkHttpClient okHttpClient ;
31
31
public HttpUrl agentUrl ;
32
32
public Monitoring monitoring ;
33
- private DDAgentFeaturesDiscovery featuresDiscovery ;
33
+ private volatile DDAgentFeaturesDiscovery featuresDiscovery ;
34
34
private ConfigurationPoller configurationPoller ;
35
35
36
36
public SharedCommunicationObjects () {
@@ -140,23 +140,27 @@ public void setFeaturesDiscovery(DDAgentFeaturesDiscovery featuresDiscovery) {
140
140
141
141
public DDAgentFeaturesDiscovery featuresDiscovery (Config config ) {
142
142
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
+ }
160
164
}
161
165
}
162
166
}
0 commit comments