From 25b29d776be85409a1fa11cb226ae1bdc3ba89fe Mon Sep 17 00:00:00 2001 From: maks2134 Date: Tue, 17 Mar 2026 00:16:00 +0300 Subject: [PATCH] Fix deadlock in ttyWriter.Done() Resolves race condition between main thread calling Done() and UI thread calling printWithDimensions(). The issue was that Done() held the mutex while sending to the done channel, but the UI thread needed the same mutex to process the done signal. Fixed by sending the done signal before acquiring the mutex, allowing the UI thread to receive the signal and release any held locks. Fixes #13639 Signed-off-by: maks2134 --- .idea/.gitignore | 8 ++++++++ .idea/compose.iml | 9 +++++++++ .idea/golinter.xml | 7 +++++++ .idea/material_theme_project_new.xml | 10 ++++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ cmd/display/tty.go | 2 +- cmd/display/tty_test.go | 21 +++++++++++++++++++++ 8 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compose.iml create mode 100644 .idea/golinter.xml create mode 100644 .idea/material_theme_project_new.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..13566b81b --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compose.iml b/.idea/compose.iml new file mode 100644 index 000000000..5e764c4f0 --- /dev/null +++ b/.idea/compose.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/golinter.xml b/.idea/golinter.xml new file mode 100644 index 000000000..1ccf3ec6d --- /dev/null +++ b/.idea/golinter.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 000000000..b1a83ad35 --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..2efec7ef0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..35eb1ddfb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/cmd/display/tty.go b/cmd/display/tty.go index 0726ce270..39e5fc946 100644 --- a/cmd/display/tty.go +++ b/cmd/display/tty.go @@ -176,13 +176,13 @@ func (w *ttyWriter) Start(ctx context.Context, operation string) { func (w *ttyWriter) Done(operation string, success bool) { w.print() + w.done <- true w.mtx.Lock() defer w.mtx.Unlock() if w.ticker != nil { w.ticker.Stop() } w.operation = "" - w.done <- true } func (w *ttyWriter) On(events ...api.Resource) { diff --git a/cmd/display/tty_test.go b/cmd/display/tty_test.go index 0bbd35f2a..f6a1a66a9 100644 --- a/cmd/display/tty_test.go +++ b/cmd/display/tty_test.go @@ -18,6 +18,7 @@ package display import ( "bytes" + "context" "strings" "sync" "testing" @@ -422,3 +423,23 @@ func TestLenAnsi(t *testing.T) { }) } } + +func TestDoneDeadlockFix(t *testing.T) { + w, _ := newTestWriter() + addTask(w, "test-task", "Working", "details", api.Working) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + w.Start(ctx, "test") + done := make(chan bool) + go func() { + w.Done("test", true) + done <- true + }() + + select { + case <-done: + case <-time.After(5 * time.Second): + t.Fatal("Deadlock detected: Done() did not complete within 5 seconds") + } +}