From d3e2e9ede295fd743c991e15789a1bc2e8d123f7 Mon Sep 17 00:00:00 2001 From: Abu Kashem Date: Thu, 30 Sep 2021 15:24:38 -0400 Subject: [PATCH] make lifecycle signal thread safe --- .../apiserver/pkg/server/lifecycle_signals.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/staging/src/k8s.io/apiserver/pkg/server/lifecycle_signals.go b/staging/src/k8s.io/apiserver/pkg/server/lifecycle_signals.go index 376167a9c58..1a939e24fe4 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/lifecycle_signals.go +++ b/staging/src/k8s.io/apiserver/pkg/server/lifecycle_signals.go @@ -16,6 +16,10 @@ limitations under the License. package server +import ( + "sync" +) + /* We make an attempt here to identify the events that take place during lifecycle of the apiserver. @@ -143,22 +147,21 @@ func newLifecycleSignals() lifecycleSignals { func newNamedChannelWrapper(name string) lifecycleSignal { return &namedChannelWrapper{ name: name, + once: sync.Once{}, ch: make(chan struct{}), } } type namedChannelWrapper struct { name string + once sync.Once ch chan struct{} } func (e *namedChannelWrapper) Signal() { - select { - case <-e.ch: - // already closed, don't close again. - default: + e.once.Do(func() { close(e.ch) - } + }) } func (e *namedChannelWrapper) Signaled() <-chan struct{} {