Skip to content

Commit

Permalink
Remote: Fix a race when reporting action progresses.
Browse files Browse the repository at this point in the history
Fixes bazelbuild#13713.

I will create checkpick request for 4.2.0 once merged into main branch.

Closes bazelbuild#13719.

PiperOrigin-RevId: 386213448
  • Loading branch information
coeuvre authored and katre committed Jul 23, 2021
1 parent 65dd9c8 commit 170e57d
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.PriorityQueue;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;

/** Tracks state for the UI. */
Expand Down Expand Up @@ -228,6 +230,7 @@ private ProgressState(String id, long nanoStartTime) {
}
}

@GuardedBy("this")
private final LinkedHashMap<String, ProgressState> runningProgresses = new LinkedHashMap<>();

/** Starts tracking the state of an action. */
Expand Down Expand Up @@ -333,6 +336,13 @@ synchronized void onProgressEvent(ActionProgressEvent event, long nanoChangeTime
state.latestEvent = event;
}

synchronized Optional<ProgressState> firstProgress() {
if (runningProgresses.isEmpty()) {
return Optional.empty();
}
return Optional.of(runningProgresses.entrySet().iterator().next().getValue());
}

/** Generates a human-readable description of this action's state. */
synchronized String describe() {
if (runningStrategiesBitmap != 0) {
Expand Down Expand Up @@ -705,12 +715,12 @@ private String describeTestGroup(
}

private String describeActionProgress(ActionState action, int desiredWidth) {
if (action.runningProgresses.isEmpty()) {
Optional<ActionState.ProgressState> stateOpt = action.firstProgress();
if (!stateOpt.isPresent()) {
return "";
}

ActionState.ProgressState state =
action.runningProgresses.entrySet().iterator().next().getValue();
ActionState.ProgressState state = stateOpt.get();
ActionProgressEvent event = state.latestEvent;
String message = event.progress();
if (message.isEmpty()) {
Expand Down

0 comments on commit 170e57d

Please sign in to comment.