Skip to content

Commit 639f89d

Browse files
Brandon Jacklyncopybara-github
Brandon Jacklyn
authored andcommitted
Fix [Prepa] actions stuck in active state
Fixed bazelbuild#13985 UiStateTracker can process ActionProgress events after an ActionCompletion event has been fired. This has the effect of recreating the action object in the activeActions Map because Map.computeIfAbsent() is being used to retrieve the action. Therefore, a new method getActionStateIfPresent is created which will return the action if it exists, otherwise return null, and actionProgress() uses this method so as to not inadverntantly recreate actions after they have already completed and been removed from the Map. Closes bazelbuild#14020. PiperOrigin-RevId: 398165993
1 parent 003e2d0 commit 639f89d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/main/java/com/google/devtools/build/lib/runtime/UiStateTracker.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,11 @@ private ActionState getActionState(
530530
return activeActions.computeIfAbsent(actionId, (key) -> new ActionState(action, nanoTimeNow));
531531
}
532532

533+
@Nullable
534+
private ActionState getActionStateIfPresent(Artifact actionId) {
535+
return activeActions.get(actionId);
536+
}
537+
533538
void actionStarted(ActionStartedEvent event) {
534539
Action action = event.getAction();
535540
Artifact actionId = action.getPrimaryOutput();
@@ -583,10 +588,12 @@ void runningAction(RunningActionEvent event) {
583588
}
584589

585590
void actionProgress(ActionProgressEvent event) {
586-
ActionExecutionMetadata action = event.action();
587591
Artifact actionId = event.action().getPrimaryOutput();
588592
long now = clock.nanoTime();
589-
getActionState(action, actionId, now).onProgressEvent(event, now);
593+
ActionState actionState = getActionStateIfPresent(actionId);
594+
if (actionState != null) {
595+
actionState.onProgressEvent(event, now);
596+
}
590597
}
591598

592599
void actionCompletion(ActionScanningCompletedEvent event) {

src/test/java/com/google/devtools/build/lib/runtime/UiStateTrackerTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ public void actionProgress_visible() throws Exception {
603603
ManualClock clock = new ManualClock();
604604
Action action = createDummyAction("Some random action");
605605
UiStateTracker stateTracker = new UiStateTracker(clock, /* targetWidth= */ 70);
606+
stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
606607
stateTracker.actionProgress(
607608
ActionProgressEvent.create(action, "action-id", "action progress", false));
608609
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true);
@@ -621,6 +622,7 @@ public void actionProgress_withTooSmallWidth_progressSkipped() throws Exception
621622
ManualClock clock = new ManualClock();
622623
Action action = createDummyAction("Some random action");
623624
UiStateTracker stateTracker = new UiStateTracker(clock, /* targetWidth= */ 30);
625+
stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
624626
stateTracker.actionProgress(
625627
ActionProgressEvent.create(action, "action-id", "action progress", false));
626628
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true);
@@ -639,6 +641,7 @@ public void actionProgress_withSmallWidth_progressShortened() throws Exception {
639641
ManualClock clock = new ManualClock();
640642
Action action = createDummyAction("Some random action");
641643
UiStateTracker stateTracker = new UiStateTracker(clock, /* targetWidth= */ 50);
644+
stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
642645
stateTracker.actionProgress(
643646
ActionProgressEvent.create(action, "action-id", "action progress", false));
644647
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true);
@@ -657,6 +660,7 @@ public void actionProgress_multipleProgress_displayInOrder() throws Exception {
657660
ManualClock clock = new ManualClock();
658661
Action action = createDummyAction("Some random action");
659662
UiStateTracker stateTracker = new UiStateTracker(clock, /* targetWidth= */ 70);
663+
stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
660664
stateTracker.actionProgress(
661665
ActionProgressEvent.create(action, "action-id1", "action progress 1", false));
662666
stateTracker.actionProgress(

0 commit comments

Comments
 (0)