From 44f17fa1c0d9bf4a20d5bc89640d2ebe7a7f3a8b Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Fri, 2 Jun 2023 12:05:33 +0200 Subject: [PATCH] fix: stop renderer before acquiring renderer mutex --- standard_renderer.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/standard_renderer.go b/standard_renderer.go index e4fb61ca9e..0ab9473d80 100644 --- a/standard_renderer.go +++ b/standard_renderer.go @@ -88,6 +88,11 @@ func (r *standardRenderer) start() { // stop permanently halts the renderer, rendering the final frame. func (r *standardRenderer) stop() { + // Stop the renderer before acquiring the mutex to avoid a deadlock. + r.once.Do(func() { + r.done <- struct{}{} + }) + // flush locks the mutex r.flush() @@ -95,9 +100,6 @@ func (r *standardRenderer) stop() { defer r.mtx.Unlock() r.out.ClearLine() - r.once.Do(func() { - r.done <- struct{}{} - }) if r.useANSICompressor { if w, ok := r.out.TTY().(io.WriteCloser); ok { @@ -108,13 +110,15 @@ func (r *standardRenderer) stop() { // kill halts the renderer. The final frame will not be rendered. func (r *standardRenderer) kill() { + // Stop the renderer before acquiring the mutex to avoid a deadlock. + r.once.Do(func() { + r.done <- struct{}{} + }) + r.mtx.Lock() defer r.mtx.Unlock() r.out.ClearLine() - r.once.Do(func() { - r.done <- struct{}{} - }) } // listen waits for ticks on the ticker, or a signal to stop the renderer.