Skip to content

Fix config being loaded twice #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ private HypertraceConfig() {}
// so avoiding for perf reasons
private static volatile boolean servletCausingException;

private static AgentConfig agentConfig;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together. I like the testability, but on the other hand, I would like to keep it as simple as possible. Would it be enough to just use volatile on this property and not use the supplier approach?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, no problem! I think in addition to making this field volatile, we would also want to synchronize the write to this field in HypertraceConfig.reset() unless you're not worried about this class being thread-safe when APIs exposed for testing purpose are in use.

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

static final String DEFAULT_SERVICE_NAME = "unknown";
static final String DEFAULT_REPORTING_ENDPOINT = "http://localhost:9411/api/v2/spans";
Expand Down Expand Up @@ -123,7 +124,9 @@ private static boolean isHypertraceType(String message) {
/** Reset the config, use only in tests. */
@VisibleForTesting
public static void reset() {
agentConfig = null;
synchronized (HypertraceConfig.class) {
agentConfig = null;
}
}

private static AgentConfig load() throws IOException {
Expand Down