@@ -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 () {
@@ -139,28 +139,34 @@ public void setFeaturesDiscovery(DDAgentFeaturesDiscovery featuresDiscovery) {
139
139
}
140
140
141
141
public DDAgentFeaturesDiscovery featuresDiscovery (Config config ) {
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 );
142
+ DDAgentFeaturesDiscovery ret = featuresDiscovery ;
143
+ if (ret == null ) {
144
+ synchronized (this ) {
145
+ if (featuresDiscovery == null ) {
146
+ createRemaining (config );
147
+ ret =
148
+ new DDAgentFeaturesDiscovery (
149
+ okHttpClient ,
150
+ monitoring ,
151
+ agentUrl ,
152
+ config .isTraceAgentV05Enabled (),
153
+ config .isTracerMetricsEnabled ());
154
+
155
+ if (paused ) {
156
+ // defer remote discovery until remote I/O is allowed
157
+ } else {
158
+ if (AGENT_THREAD_GROUP .equals (Thread .currentThread ().getThreadGroup ())) {
159
+ ret .discover (); // safe to run on same thread
160
+ } else {
161
+ // avoid performing blocking I/O operation on application thread
162
+ AgentTaskScheduler .INSTANCE .execute (ret ::discover );
163
+ }
164
+ }
165
+ featuresDiscovery = ret ;
160
166
}
161
167
}
162
168
}
163
- return featuresDiscovery ;
169
+ return ret ;
164
170
}
165
171
166
172
private static final class FixedConfigUrlSupplier implements Supplier <String > {
0 commit comments