From d7a257b39177eea973a02f74cd808eef1f89ca98 Mon Sep 17 00:00:00 2001 From: greatroar <61184462+greatroar@users.noreply.github.com> Date: Mon, 30 Mar 2020 15:10:08 +0200 Subject: [PATCH] lib/util: Fix potential data race (#6477) Co-authored-by: greatroar <@> --- lib/util/utils.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/util/utils.go b/lib/util/utils.go index 4990af7c7..1851aa035 100644 --- a/lib/util/utils.go +++ b/lib/util/utils.go @@ -255,8 +255,12 @@ func (s *service) Stop() { default: s.cancel() } + + // Cache s.stopped in a variable while we hold the mutex + // to prevent a data race with Serve's resetting it. + stopped := s.stopped s.mut.Unlock() - <-s.stopped + <-stopped } func (s *service) Error() error {