Skip to content

Commit 33bc28f

Browse files
authored
Fix config being loaded twice (hypertrace#293)
* ✨ create memoizing AgentConfigSupplier encapsulating double-checked locking logic * ♻️ refactor HypertraceConfig to use thread-safe AgentConfigSupplier * Revert "♻️ refactor HypertraceConfig to use thread-safe AgentConfigSupplier" This reverts commit 19ad84b. * 👌 move double-checked locking implementation back into HypertraceConfig * 🔥 delete AgentConfigSupplier as it is now unused
1 parent 13494b4 commit 33bc28f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

javaagent-core/src/main/java/org/hypertrace/agent/core/config/HypertraceConfig.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ private HypertraceConfig() {}
5151
// so avoiding for perf reasons
5252
private static volatile boolean servletCausingException;
5353

54-
private static AgentConfig agentConfig;
54+
// volatile field in order to properly handle lazy initialization with double-checked locking
55+
private static volatile AgentConfig agentConfig;
5556

5657
static final String DEFAULT_SERVICE_NAME = "unknown";
5758
static final String DEFAULT_REPORTING_ENDPOINT = "http://localhost:9411/api/v2/spans";
@@ -123,7 +124,9 @@ private static boolean isHypertraceType(String message) {
123124
/** Reset the config, use only in tests. */
124125
@VisibleForTesting
125126
public static void reset() {
126-
agentConfig = null;
127+
synchronized (HypertraceConfig.class) {
128+
agentConfig = null;
129+
}
127130
}
128131

129132
private static AgentConfig load() throws IOException {

0 commit comments

Comments
 (0)