Skip to content

Commit a56d10f

Browse files
fix: use synchronized instead of atomic refs in bridge
1 parent 098b929 commit a56d10f

File tree

2 files changed

+23
-38
lines changed

2 files changed

+23
-38
lines changed

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/Agent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,6 @@ public void execute() {
632632
}
633633

634634
maybeStartAppSec(scoClass, sco);
635-
// start civisibility before debugger to enable Failed Test Replay correctly in headless mode
636635
maybeStartCiVisibility(instrumentation, scoClass, sco);
637636
maybeStartLLMObs(instrumentation, scoClass, sco);
638637
// start debugger before remote config to subscribe to it before starting to poll
Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,71 @@
11
package datadog.trace.api.debugger;
22

33
import datadog.trace.api.Config;
4-
import java.util.concurrent.atomic.AtomicReference;
54
import javax.annotation.Nonnull;
65
import org.slf4j.Logger;
76
import org.slf4j.LoggerFactory;
87

98
public final class DebuggerConfigBridge {
109
private static final Logger LOGGER = LoggerFactory.getLogger(DebuggerConfigBridge.class);
1110

12-
private static final AtomicReference<DebuggerConfigUpdate> DEFERRED_UPDATE =
13-
new AtomicReference<>();
11+
private static DebuggerConfigUpdate DEFERRED_UPDATE;
12+
private static volatile DebuggerConfigUpdater UPDATER;
1413

15-
private static final AtomicReference<DebuggerConfigUpdater> UPDATER = new AtomicReference<>();
16-
17-
public static void updateConfig(DebuggerConfigUpdate update) {
14+
public static synchronized void updateConfig(DebuggerConfigUpdate update) {
1815
if (!update.hasUpdates()) {
1916
LOGGER.debug("No config update detected, skipping");
2017
return;
2118
}
22-
DebuggerConfigUpdater updater = UPDATER.get();
23-
if (updater != null) {
19+
if (UPDATER != null) {
2420
LOGGER.debug("DebuggerConfigUpdater available, performing update: {}", update);
25-
updater.updateConfig(update);
21+
UPDATER.updateConfig(update);
2622
} else {
2723
LOGGER.debug("DebuggerConfigUpdater not available, deferring update");
28-
DEFERRED_UPDATE.updateAndGet(existing -> DebuggerConfigUpdate.coalesce(existing, update));
24+
DEFERRED_UPDATE = DebuggerConfigUpdate.coalesce(DEFERRED_UPDATE, update);
2925
}
3026
}
3127

32-
public static void setUpdater(@Nonnull DebuggerConfigUpdater updater) {
33-
DebuggerConfigUpdater oldUpdater = UPDATER.getAndSet(updater);
34-
if (oldUpdater == null) {
35-
LOGGER.debug("DebuggerConfigUpdater set for first time, processing deferred updates");
36-
processDeferredUpdate(updater);
28+
public static synchronized void setUpdater(@Nonnull DebuggerConfigUpdater updater) {
29+
UPDATER = updater;
30+
if (DEFERRED_UPDATE != null && DEFERRED_UPDATE.hasUpdates()) {
31+
DebuggerConfigUpdate toApply = DEFERRED_UPDATE;
32+
DEFERRED_UPDATE = null;
33+
LOGGER.debug("Processing deferred update {}", toApply);
34+
updater.updateConfig(toApply);
3735
}
3836
}
3937

4038
// for testing purposes
4139
static void reset() {
42-
UPDATER.set(null);
43-
DEFERRED_UPDATE.set(null);
40+
UPDATER = null;
41+
DEFERRED_UPDATE = null;
4442
}
4543

4644
public static boolean isDynamicInstrumentationEnabled() {
47-
DebuggerConfigUpdater updater = UPDATER.get();
48-
if (updater != null) {
49-
return updater.isDynamicInstrumentationEnabled();
45+
if (UPDATER != null) {
46+
return UPDATER.isDynamicInstrumentationEnabled();
5047
}
5148
return Config.get().isDynamicInstrumentationEnabled();
5249
}
5350

5451
public static boolean isExceptionReplayEnabled() {
55-
DebuggerConfigUpdater updater = UPDATER.get();
56-
if (updater != null) {
57-
return updater.isExceptionReplayEnabled();
52+
if (UPDATER != null) {
53+
return UPDATER.isExceptionReplayEnabled();
5854
}
5955
return Config.get().isDebuggerExceptionEnabled();
6056
}
6157

6258
public static boolean isCodeOriginEnabled() {
63-
DebuggerConfigUpdater updater = UPDATER.get();
64-
if (updater != null) {
65-
return updater.isCodeOriginEnabled();
59+
if (UPDATER != null) {
60+
return UPDATER.isCodeOriginEnabled();
6661
}
6762
return Config.get().isDebuggerCodeOriginEnabled();
6863
}
6964

7065
public static boolean isDistributedDebuggerEnabled() {
71-
DebuggerConfigUpdater updater = UPDATER.get();
72-
if (updater != null) {
73-
return updater.isDistributedDebuggerEnabled();
66+
if (UPDATER != null) {
67+
return UPDATER.isDistributedDebuggerEnabled();
7468
}
7569
return Config.get().isDistributedDebuggerEnabled();
7670
}
77-
78-
private static void processDeferredUpdate(DebuggerConfigUpdater updater) {
79-
DebuggerConfigUpdate deferredUpdate = DEFERRED_UPDATE.getAndSet(null);
80-
if (deferredUpdate != null) {
81-
updater.updateConfig(deferredUpdate);
82-
LOGGER.debug("Processed deferred update {}", deferredUpdate);
83-
}
84-
}
8571
}

0 commit comments

Comments
 (0)