Skip to content

Commit 80856ea

Browse files
authored
progress: minor correctness fixes (docker#10871)
* When waiting for dependencies, `select` on the context as well as the ticker * Write multiple progress events "transactionally" (i.e. hold the lock for the duration to avoid other events being interleaved) * Do not change "finished" steps back to "in progress" to prevent flickering Signed-off-by: Milas Bowman <[email protected]>
1 parent d7b1972 commit 80856ea

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

pkg/compose/convergence.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
324324
ticker := time.NewTicker(500 * time.Millisecond)
325325
defer ticker.Stop()
326326
for {
327-
<-ticker.C
327+
select {
328+
case <-ticker.C:
329+
case <-ctx.Done():
330+
return nil
331+
}
328332
switch config.Condition {
329333
case ServiceConditionRunningOrHealthy:
330334
healthy, err := s.isServiceHealthy(ctx, waitingFor, true)

pkg/progress/tty.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,25 @@ func (w *ttyWriter) Stop() {
7373
func (w *ttyWriter) Event(e Event) {
7474
w.mtx.Lock()
7575
defer w.mtx.Unlock()
76+
w.event(e)
77+
}
78+
79+
func (w *ttyWriter) event(e Event) {
7680
if !utils.StringContains(w.eventIDs, e.ID) {
7781
w.eventIDs = append(w.eventIDs, e.ID)
7882
}
7983
if _, ok := w.events[e.ID]; ok {
8084
last := w.events[e.ID]
8185
switch e.Status {
8286
case Done, Error, Warning:
83-
if last.Status != e.Status {
87+
if last.endTime.IsZero() {
8488
last.stop()
8589
}
90+
case Working:
91+
if !last.endTime.IsZero() {
92+
// already done, don't overwrite
93+
return
94+
}
8695
}
8796
last.Status = e.Status
8897
last.Text = e.Text
@@ -106,8 +115,10 @@ func (w *ttyWriter) Event(e Event) {
106115
}
107116

108117
func (w *ttyWriter) Events(events []Event) {
118+
w.mtx.Lock()
119+
defer w.mtx.Unlock()
109120
for _, e := range events {
110-
w.Event(e)
121+
w.event(e)
111122
}
112123
}
113124

0 commit comments

Comments
 (0)