Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion cmd/display/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func (w *ttyWriter) Start(ctx context.Context, operation string) {

func (w *ttyWriter) Done(operation string, success bool) {
w.print()
w.done <- true
// close never blocks if the render goroutine already exited via ctx.Done()
close(w.done)
w.mtx.Lock()
defer w.mtx.Unlock()
if w.ticker != nil {
Expand Down
20 changes: 20 additions & 0 deletions cmd/display/tty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,26 @@ func TestDoneDeadlockFix(t *testing.T) {
}
}

func TestDoneAfterContextCancelDoesNotHang(t *testing.T) {
w, _ := newTestWriter()
ctx, cancel := context.WithCancel(context.Background())
w.Start(ctx, "down")
cancel()
// Let the render goroutine observe the cancellation and exit.
time.Sleep(100 * time.Millisecond)

finished := make(chan struct{})
go func() {
w.Done("down", false)
close(finished)
}()
select {
case <-finished:
case <-time.After(2 * time.Second):
t.Fatal("ttyWriter.Done blocked forever after context cancellation")
}
}

// TestAdjustLineWidth_WideProgressForcesSizeInfoDrop is the unit-level
// regression test for docker/compose#13595. When progress contains the
// " X.XMB / Y.YMB" size suffix and the bar makes beforeStatus large enough
Expand Down