From 506d39912ca2ffe1fd9b74bfaa097c46f656d86e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 23 Apr 2020 14:34:00 +0200 Subject: [PATCH] Fix data race with struct access after calling `Stop()` We need to obtain a lock before accessing `s.active` because `Stop()` might write to it at the same time. --- spinner.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spinner.go b/spinner.go index 9d0c128..ba30966 100644 --- a/spinner.go +++ b/spinner.go @@ -285,10 +285,11 @@ func (s *Spinner) Start() { case <-s.stopChan: return default: + s.mu.Lock() if !s.active { + s.mu.Unlock() return } - s.mu.Lock() s.erase() if s.PreUpdate != nil {