Browse Source

lib/util: Fix potential data race (#6477)

Co-authored-by: greatroar <@>
greatroar 5 years ago
parent
commit
d7a257b391
1 changed files with 5 additions and 1 deletions
  1. 5 1
      lib/util/utils.go

+ 5 - 1
lib/util/utils.go

@@ -255,8 +255,12 @@ func (s *service) Stop() {
 	default:
 	default:
 		s.cancel()
 		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.mut.Unlock()
-	<-s.stopped
+	<-stopped
 }
 }
 
 
 func (s *service) Error() error {
 func (s *service) Error() error {