From a30c0f477d9d4813a08e0abdc7b9029bd4a29287 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Mon, 6 Nov 2017 15:37:07 +0100 Subject: [PATCH] apiserver: fix Cacher.Stop() race --- staging/src/k8s.io/apiserver/pkg/storage/cacher.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher.go index 8167aaffe37..e3c787d0842 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher.go @@ -649,13 +649,15 @@ func (c *Cacher) isStopped() bool { } func (c *Cacher) Stop() { - // TODO : Do not check for isStopped (and return) when PR - // https://github.com/kubernetes/kubernetes/pull/50690 - // merges as that shuts down storage properly + // avoid stopping twice (note: cachers are shared with subresources) if c.isStopped() { return } c.stopLock.Lock() + if c.stopped { + // avoid that it was locked meanwhile as isStopped only read-locks + return + } c.stopped = true c.stopLock.Unlock() close(c.stopCh)