Skip to content
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

Trace Stapler request processing #148

Merged
merged 3 commits into from
Oct 11, 2018
Merged

Conversation

daniel-beck
Copy link
Member

@daniel-beck daniel-beck commented Oct 9, 2018

Upstream from jenkinsci/jenkins#3688

@daniel-beck
Copy link
Member Author

3b3105f (plus a local versions:set) deployed as 1.255-telemetry-1-SNAPSHOT.

jglick
jglick previously requested changes Oct 11, 2018
private static List<ApplicationTracer> getTracers() {
if (tracers == null) {
synchronized (ApplicationTracer.class) {
if (tracers == null) {
Copy link
Member

Choose a reason for hiding this comment

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

Double-checked locking. Delete the outer null check.

@daniel-beck daniel-beck requested a review from jglick October 11, 2018 12:50
@daniel-beck
Copy link
Member Author

d33d285?w=1

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

Not what I had in mind, but at least no longer apparently vulnerable to data corruption.

}
}

private static volatile List<ApplicationTracer> tracers;
Copy link
Member

Choose a reason for hiding this comment

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

Pointless for this to be volatile, since you have the synchronized block.

tracers = t;
}
}
return tracers;
Copy link
Member

Choose a reason for hiding this comment

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

This should really be inside the synchronized block. I think it is harmless to have it outside, since there will be a synchronization barrier before, but definitely not the best style.

private static List<ApplicationTracer> getTracers() {
synchronized (ApplicationTracer.class) {
if (tracers == null) {
List<ApplicationTracer> t = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

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

You do not need a separate variable. You can initialize tracers directly, since it is protected by a synchronization barrier.

@jglick
Copy link
Member

jglick commented Oct 11, 2018

FTR all you need is something like:

private static List<X> xs;
static synchronized List<X> xs() {
  if (xs == null) {
    xs = new ArrayList<>();
    // populate xs
  }
  return xs;
}

Simple and safe.

@jglick jglick dismissed their stale review October 11, 2018 12:57

no longer a hazard

@jglick jglick merged commit d33d285 into jenkinsci:master Oct 11, 2018
jglick added a commit that referenced this pull request Oct 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants